-
Notifications
You must be signed in to change notification settings - Fork 0
/
pokeset.rb
51 lines (42 loc) · 857 Bytes
/
pokeset.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class Pokeset
include Comparable
def initialize(set = [])
@set = set
end
def <=>(other)
if other.nil?
1
elsif length != other.length
length <=> other.length
elsif total_length != other.total_length
total_length <=> other.total_length
else
0
end
end
def code
@code ||= begin
code = 0
@set.map(&:code).each { |c| code |= c }
code
end
end
def chars
@chars ||= @set.map(&:unique_chars).flatten.uniq
end
def length
@length ||= @set.length
end
def total_length
@total_length ||= @set.map(&:name).join.length
end
def set
@set
end
def to_s
@string ||= "#{@set.join ', '}, for a total length of #{length} pokemon and #{total_length} characters"
end
def missing_char_count
@missing_char_count ||= 26 - chars.length
end
end