Class: Enumpath::Operator::Child
- Defined in:
- lib/enumpath/operator/child.rb
Overview
Implements JSONPath child operator syntax. See README for syntax and examples.
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
-
.detect?(operator, enum) ⇒ true, false
Checks to see if an operator is valid as a child operator.
Instance Method Summary collapse
-
#apply(remaining_path, enum, resolved_path) {|remaining_path, enum, resolved_path| ... } ⇒ Object
Resolves a child operator against an enumerable.
-
#detect?(enum) ⇒ true, false
Whether the operator resolves against an enumerable.
Methods inherited from Base
Constructor Details
This class inherits a constructor from Enumpath::Operator::Base
Class Method Details
.detect?(operator, enum) ⇒ true, false
Checks to see if an operator is valid as a child operator. It is considered valid if the enumerable contains an index, key, member, or property that responds to child.
13 14 15 |
# File 'lib/enumpath/operator/child.rb', line 13 def detect?(operator, enum) !resolve(operator, enum).nil? end |
Instance Method Details
#apply(remaining_path, enum, resolved_path) {|remaining_path, enum, resolved_path| ... } ⇒ Object
Resolves a child operator against an enumerable. If the child operator matches a index, key, member, or property of the enumerable it is yielded to the block.
63 64 65 66 |
# File 'lib/enumpath/operator/child.rb', line 63 def apply(remaining_path, enum, resolved_path) value = detected_value(enum) yield(remaining_path, value, resolved_path + [operator]) unless value.nil? end |
#detect?(enum) ⇒ true, false
Whether the operator resolves against an enumerable. The resolved value is kept, so a following #apply to the same enumerable uses it instead of resolving the operator a second time. That matters when a property resolver policy lets the operator call a method, which must run once per path segment.
50 51 52 53 |
# File 'lib/enumpath/operator/child.rb', line 50 def detect?(enum) keep(enum, self.class.resolve(operator, enum)) !@detected_value.nil? end |