Class: Enumpath::Operator::Wildcard

Inherits:
Base
  • Object
show all
Defined in:
lib/enumpath/operator/wildcard.rb

Overview

Implements JSONPath wildcard operator syntax. See README for syntax and examples

Constant Summary collapse

OPERATOR =
'*'

Instance Attribute Summary

Attributes inherited from Base

#operator

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Enumpath::Operator::Base

Class Method Details

.detect?(operator) ⇒ true, false

Simple test of whether the operator matches the OPERATOR constant

Parameters:

  • operator (String)

    the the full, normalized operator to test

Returns:

  • (true, false)

    whether the operator param appears to represent the operator class



14
15
16
# File 'lib/enumpath/operator/wildcard.rb', line 14

def detect?(operator)
  operator == OPERATOR
end

Instance Method Details

#apply(remaining_path, enum, resolved_path) {|remaining_path, enum, resolved_path| ... } ⇒ Object

Yields to the block once for every direct member of the enumerable

Parameters:

  • remaining_path (Array)

    an array containing the normalized path segments yet to be resolved

  • enum (Enumerable)

    the object to apply the operator to

  • resolved_path (Array)

    an array containing the static path segments that have been resolved

Yields:

  • A block that will be called if the operator is applied successfully. If the operator cannot or should not be applied then the block is not yielded.

Yield Parameters:

  • remaining_path (Array)

    the key of the given member plus remaining_path

  • enum (Enumerable)

    enum

  • resolved_path (Array)

    resolved_path



26
27
28
29
30
# File 'lib/enumpath/operator/wildcard.rb', line 26

def apply(remaining_path, enum, resolved_path)
  keys = keys(enum)
  Enumpath.log('Applying wildcard to keys') { { keys: keys } }
  keys.each { |key| yield([key.to_s] + remaining_path, enum, resolved_path) }
end