Class: Arspy::Operators::Selector::HashSelector

Inherits:
Base
  • Object
show all
Defined in:
lib/arspy/operators/selector/hash_selector.rb

Constant Summary collapse

@@hash_selector_classes =
[
  Selector::AttributeSelector,
  Selector::UnsupportedSelector
]

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

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

Class Method Details

.applies?(arg) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/arspy/operators/selector/hash_selector.rb', line 10

def self.applies?(arg)
  arg.is_a? Hash
end

Instance Method Details

#hash_selector_class_for(key_value) ⇒ Object



23
24
25
# File 'lib/arspy/operators/selector/hash_selector.rb', line 23

def hash_selector_class_for(key_value)
  @@hash_selector_classes.detect{|klass| klass.applies?(key_value) }
end

#select?(obj) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/arspy/operators/selector/hash_selector.rb', line 14

def select?(obj)
  selectors.any?{|selector| selector.select?(obj) }
end

#selectorsObject



18
19
20
21
22
# File 'lib/arspy/operators/selector/hash_selector.rb', line 18

def selectors
  @selectors ||= @argument.map do |key_value|
    hash_selector_class_for(key_value).new(key_value)
  end
end