Class: Plant::Selector::ArrayCollection

Inherits:
BlankSlate
  • Object
show all
Defined in:
lib/selector.rb

Instance Method Summary collapse

Constructor Details

#initialize(collection) ⇒ ArrayCollection

Returns a new instance of ArrayCollection.



49
50
51
# File 'lib/selector.rb', line 49

def initialize collection
  @collection = collection
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/selector.rb', line 58

def method_missing method, *args, &block
  if (@method)
    return compare(method, *args)
  end
  @method = method
  self
end

Instance Method Details

#compare(operator, operand) ⇒ Object



53
54
55
56
# File 'lib/selector.rb', line 53

def compare operator, operand
  collection = @collection.dup
  collection.map{|object| Attribute.new(object, @method)}.any? {|object| object.send(operator, operand) }
end