Method: Janeway.enum_for

Defined in:
lib/janeway.rb

.enum_for(jsonpath, data) ⇒ Janeway::Enumerator

Parse a jsonpath string and combine it with data to make an Enumerator.

The Enumerator can be used to apply the query to the data using Enumerator module methods such as #each and #map.

Examples:

Apply query to data and search to get array of results

results = Janeway.parse('$.store.books[? length(@.title) > 20]').search

Apply query to data and iterate over results

enum = Janeway.parse('$.store.books[? length(@.title) > 20]')
enum.each do |book|
  results << book
end

Parameters:

  • jsonpath (String)

    jsonpath query

  • data (Array, Hash)

    input data

Returns:

See Also:



30
31
32
33
# File 'lib/janeway.rb', line 30

def self.enum_for(jsonpath, data)
  query = parse(jsonpath)
  Janeway::Enumerator.new(query, data)
end