Class: Arspy::Operators::Interpreter::AttributeInterpreter

Inherits:
Base
  • Object
show all
Defined in:
lib/arspy/operators/interpreter/attribute_interpreter.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Arspy::Operators::Interpreter::Base

Class Method Details

.applies?(array, method_name) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/arspy/operators/interpreter/attribute_interpreter.rb', line 6

def self.applies?(array, method_name)
  array.first.attribute_names.include?(method_name.to_s)
end

Instance Method Details

#interpret(*args) ⇒ Object



10
11
12
13
14
15
# File 'lib/arspy/operators/interpreter/attribute_interpreter.rb', line 10

def interpret(*args)
  return @array.map(&@method_name) if args.empty?
  raise 'Hash not supported as attribute conditionals' if args.any?{|arg| arg.is_a?(Hash)}
  selector = Selector.for({@method_name => args})
  @array.select{|obj| obj && selector.select?(obj)}
end