class Infoboxer::Navigation::Lookup::Selector
Incapsulates storage of selectors, used in {Lookup::Node node lookup}.
See {Lookup::Node Lookup::Node} for detailed explanation of available selectors.
Attributes
arg[R]
Public Class Methods
new(*arg, &block)
click to toggle source
# File lib/infoboxer/navigation/selector.rb, line 10 def initialize(*arg, &block) @arg = [arg, block].flatten.compact.map(&method(:sym_to_class)) @arg.each do |a| a.compact! if a.is_a?(Hash) end end
Public Instance Methods
==(other)
click to toggle source
# File lib/infoboxer/navigation/selector.rb, line 19 def ==(other) self.class == other.class && arg == other.arg end
===(other)
click to toggle source
# File lib/infoboxer/navigation/selector.rb, line 27 def ===(other) @arg.all? { |a| arg_matches?(a, other) } end
inspect()
click to toggle source
# File lib/infoboxer/navigation/selector.rb, line 23 def inspect "#<Selector(#{@arg.map(&:to_s).join(', ')})>" end
Private Instance Methods
arg_matches?(check, node)
click to toggle source
# File lib/infoboxer/navigation/selector.rb, line 41 def arg_matches?(check, node) case check when Proc check.call(node) when Hash check.all? { |attr, value| node.respond_to?(attr) && value_matches?(value, node.send(attr)) || node.params.key?(attr) && value_matches?(value, node.params[attr]) } when Symbol node.respond_to?(check) && node.send(check) else check === node end end
sym_to_class(a)
click to toggle source
# File lib/infoboxer/navigation/selector.rb, line 33 def sym_to_class(a) if a.is_a?(Symbol) && a =~ /^[A-Z][a-zA-Z]+$/ && Tree.const_defined?(a) Tree.const_get(a) else a end end
value_matches?(matcher, value)
click to toggle source
# File lib/infoboxer/navigation/selector.rb, line 57 def value_matches?(matcher, value) if matcher.is_a?(String) && value.is_a?(String) matcher.casecmp(value).zero? else matcher === value end end