Class: Janeway::Enumerator
- Inherits:
-
Object
- Object
- Janeway::Enumerator
- Includes:
- Enumerable
- Defined in:
- lib/janeway/enumerator.rb
Overview
Enumerator combines a parsed JSONpath query with input. It provides enumerator methods.
Instance Method Summary collapse
-
#delete ⇒ Array, Hash
Delete each value matched by the JSONPath query.
-
#each {|value, parent, hash, normalized| ... } ⇒ void
Iterate through each value matched by the JSONPath query.
-
#initialize(query, input) ⇒ Enumerator
constructor
A new instance of Enumerator.
-
#search ⇒ Array
Return a list of values from the input data that match the jsonpath query.
Constructor Details
#initialize(query, input) ⇒ Enumerator
Returns a new instance of Enumerator.
10 11 12 13 14 15 |
# File 'lib/janeway/enumerator.rb', line 10 def initialize(query, input) @query = query @input = input raise ArgumentError, "expect Janeway::Query, got #{query.inspect}" unless query.is_a?(Query) end |
Instance Method Details
#delete ⇒ Array, Hash
Delete each value matched by the JSONPath query.
39 40 41 |
# File 'lib/janeway/enumerator.rb', line 39 def delete Janeway::Interpreter.new(@query, as: :deleter).interpret(@input) end |
#each {|value, parent, hash, normalized| ... } ⇒ void
This method returns an undefined value.
Iterate through each value matched by the JSONPath query.
31 32 33 34 35 |
# File 'lib/janeway/enumerator.rb', line 31 def each(&block) return enum_for(:each) unless block_given? Janeway::Interpreter.new(@query, as: :iterator, &block).interpret(@input) end |
#search ⇒ Array
Return a list of values from the input data that match the jsonpath query
20 21 22 |
# File 'lib/janeway/enumerator.rb', line 20 def search Janeway::Interpreter.new(@query).interpret(@input) end |