Module: HashQuery::Extension
- Included in:
- Hash
- Defined in:
- lib/hash_query.rb
Instance Method Summary collapse
- #query_value(selectors) ⇒ Object
-
#query_values(selectors) ⇒ Object
Public: Scans the hash data strucure looking for keys that match the psuedo css selector.
Instance Method Details
#query_value(selectors) ⇒ Object
47 48 49 50 |
# File 'lib/hash_query.rb', line 47 def query_value(selectors) values = query_values(selectors) values && values.first end |
#query_values(selectors) ⇒ Object
Public: Scans the hash data strucure looking for keys that match the psuedo css selector.
selectors - String of pseudo css selectors to navigate hash structure
Examples
entity = {
:a => 1,
:b => {
:c => {
:d => {
:e => 2,
:f => 3
}
},
:cc => [
3,
{
:g => 6,
:h => 7,
:i => [ 8, 9, 10, 11 ]
},
4,
5
]
}
}.to_entity
entity.query('a') # => 1
entity.query('a b c d e') # => 2
entity.query('c d e') # => 2
entity.query('a>string')
entity.query('a:string')
Returns a value or collection of values that are found.
42 43 44 45 |
# File 'lib/hash_query.rb', line 42 def query_values(selectors) @_query ||= HashQuery::Query.new(self) @_query.query(selectors) end |