Class: Janeway::Interpreters::DescendantSegmentInterpreter
- Defined in:
- lib/janeway/interpreters/descendant_segment_interpreter.rb
Overview
Find all descendants of the current input that match the selector in the DescendantSegment
Constant Summary
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#interpret(input, root) ⇒ Array<AST::Expression>
Find all descendants of the current input that match the selector in the DescendantSegment.
-
#visit(input, &action) ⇒ Object
Visit all descendants of ‘input`.
Methods inherited from Base
Constructor Details
This class inherits a constructor from Janeway::Interpreters::Base
Instance Method Details
#interpret(input, root) ⇒ Array<AST::Expression>
Find all descendants of the current input that match the selector in the DescendantSegment
16 17 18 19 20 |
# File 'lib/janeway/interpreters/descendant_segment_interpreter.rb', line 16 def interpret(input, root) visit(input) do |node| @next.interpret(node, root) end end |
#visit(input, &action) ⇒ Object
Visit all descendants of ‘input`. Return results of applying `action` on each.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/janeway/interpreters/descendant_segment_interpreter.rb', line 24 def visit(input, &action) results = [yield(input)] case input when Array results.concat(input.map { |elt| visit(elt, &action) }) when Hash results.concat(input.values.map { |value| visit(value, &action) }) else input end results.flatten(1).compact end |