Class: HashQuery::Selector
- Inherits:
-
Object
- Object
- HashQuery::Selector
- Defined in:
- lib/hash_query.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(matcher) ⇒ Selector
constructor
A new instance of Selector.
- #match!(node) ⇒ Object
- #match?(node) ⇒ Boolean
Constructor Details
#initialize(matcher) ⇒ Selector
Returns a new instance of Selector.
116 117 118 119 |
# File 'lib/hash_query.rb', line 116 def initialize(matcher) @key, @type = matcher.split(':') @type = Object.module_eval("::#{@type.capitalize}", __FILE__, __LINE__) if @type end |
Class Method Details
.parse(selectors) ⇒ Object
112 113 114 |
# File 'lib/hash_query.rb', line 112 def self.parse(selectors) selectors.split(/ /).map { |matcher| new(matcher) } end |
Instance Method Details
#match!(node) ⇒ Object
125 126 127 |
# File 'lib/hash_query.rb', line 125 def match!(node) node[@key] end |
#match?(node) ⇒ Boolean
121 122 123 |
# File 'lib/hash_query.rb', line 121 def match?(node) node.has_key?(@key) && (!@type || node[@key].is_a?(@type)) end |