class Enumpath::Operator::RecursiveDescent

Implements JSONPath recursive descent operator syntax. See {file:README.md#label-Recursive+descent+operator} for syntax and examples

Constants

OPERATOR

Public Class Methods

detect?(operator) click to toggle source

Simple test of whether the operator matches the {Enumpath::Operator::RecursiveDescent::OPERATOR} constant

@param operator (see Enumpath::Operator::Base.detect?) @return (see Enumpath::Operator::Base.detect?)

# File lib/enumpath/operator/recursive_descent.rb, line 15
def detect?(operator)
  operator == OPERATOR
end

Public Instance Methods

apply(remaining_path, enum, resolved_path) { |remaining_path, enum, resolved_path| ... } click to toggle source

Yields to the block once for the enumerable itself, and once for every direct member of the enumerable that is also an enumerable

@param (see Enumpath::Operator::Base#apply) @yield (see Enumpath::Operator::Base#apply) @yieldparam remaining_path [Array] remaining_path for the enumerable itself, or the recursive descent

operator plus remaining_path for each direct enumerable member

@yieldparam enum [Enumerable] enum for the enumerable itself, or the direct enumerable member for each direct

enumerable member

@yieldparam resolved_path [Array] resolved_path for the enumerable itself, or resolved_path plus the key for

each direct enumerable member
# File lib/enumpath/operator/recursive_descent.rb, line 31
def apply(remaining_path, enum, resolved_path)
  Enumpath.log('Applying remaining path recursively to enum') { { 'remaining path': remaining_path } }
  yield(remaining_path, enum, resolved_path)
  keys(enum).each do |key|
    value = Enumpath::Resolver::Simple.resolve(key, enum)
    next unless recursable?(value)

    Enumpath.log('Applying remaining path recursively to key') do
      { key: key, 'remaining path': ['..'] + remaining_path }
    end
    yield(['..'] + remaining_path, value, resolved_path + [key])
  end
end

Private Instance Methods

recursable?(value) click to toggle source
# File lib/enumpath/operator/recursive_descent.rb, line 47
def recursable?(value)
  value.is_a?(Enumerable)
end