class Enumerize::Set
Attributes
values[R]
Public Class Methods
new(obj, attr, values)
click to toggle source
# File lib/enumerize/set.rb, line 12 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
Public Instance Methods
<<(value)
click to toggle source
# File lib/enumerize/set.rb, line 28 def <<(value) @values << value mutate! end
Also aliased as: push
==(other)
click to toggle source
# File lib/enumerize/set.rb, line 47 def ==(other) return false unless other.respond_to?(:each) other.size == size && other.all? { |v| @values.include?(@attr.find_value(v)) } end
Also aliased as: eql?
delete(value)
click to toggle source
# File lib/enumerize/set.rb, line 58 def delete(value) @values.delete(@attr.find_value(value)) mutate! end
encode_with(coder)
click to toggle source
# File lib/enumerize/set.rb, line 67 def encode_with(coder) coder.represent_object(Array, @values) end
include?(value)
click to toggle source
# File lib/enumerize/set.rb, line 54 def include?(value) @values.include?(@attr.find_value(value)) end
inspect()
click to toggle source
# File lib/enumerize/set.rb, line 63 def inspect "#<Enumerize::Set {#{join(', ')}}>" end
texts()
click to toggle source
# File lib/enumerize/set.rb, line 41 def texts @values.map(&:text) end
to_ary()
click to toggle source
# File lib/enumerize/set.rb, line 37 def to_ary @values.to_a end
Private Instance Methods
mutate!()
click to toggle source
# File lib/enumerize/set.rb, line 77 def mutate! @values = @obj.public_send("#{@attr.name}=", @values).values end
predicate_call(value)
click to toggle source
# File lib/enumerize/set.rb, line 73 def predicate_call(value) include?(value) end