Class: Enumerize::Set
Instance Attribute Summary collapse
Instance Method Summary
collapse
#respond_to_missing?
Constructor Details
#initialize(obj, attr, values) ⇒ Set
Returns a new instance of Set.
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/enumerize/set.rb', line 10
def initialize(obj, attr, values)
@obj = obj
@attr = attr
@values = []
if values.respond_to?(:each)
values.each do |input|
value = @attr.find_value(input)
if value && !@values.include?(value)
@values << value
end
end
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Enumerize::Predicatable
Instance Attribute Details
#values ⇒ Object
Returns the value of attribute values.
8
9
10
|
# File 'lib/enumerize/set.rb', line 8
def values
@values
end
|
Instance Method Details
#<<(value) ⇒ Object
Also known as:
push
26
27
28
29
|
# File 'lib/enumerize/set.rb', line 26
def <<(value)
@values << value
mutate!
end
|
#==(other) ⇒ Object
Also known as:
eql?
45
46
47
48
|
# File 'lib/enumerize/set.rb', line 45
def ==(other)
return false unless other.respond_to?(:each)
other.size == size && other.all? { |v| @values.include?(@attr.find_value(v)) }
end
|
#delete(value) ⇒ Object
56
57
58
59
|
# File 'lib/enumerize/set.rb', line 56
def delete(value)
@values.delete(@attr.find_value(value))
mutate!
end
|
#encode_with(coder) ⇒ Object
65
66
67
|
# File 'lib/enumerize/set.rb', line 65
def encode_with(coder)
coder.represent_object(Array, @values)
end
|
#include?(value) ⇒ Boolean
52
53
54
|
# File 'lib/enumerize/set.rb', line 52
def include?(value)
@values.include?(@attr.find_value(value))
end
|
#inspect ⇒ Object
61
62
63
|
# File 'lib/enumerize/set.rb', line 61
def inspect
"#<Enumerize::Set {#{join(', ')}}>"
end
|
#texts ⇒ Object
39
40
41
|
# File 'lib/enumerize/set.rb', line 39
def texts
@values.map(&:text)
end
|
#to_ary ⇒ Object
35
36
37
|
# File 'lib/enumerize/set.rb', line 35
def to_ary
@values.to_a
end
|