Class: Janeway::Interpreters::ChildSegmentInterpreter

Inherits:
Base
  • Object
show all
Defined in:
lib/janeway/interpreters/child_segment_interpreter.rb

Overview

For each node in the input nodelist, the resulting nodelist of a child segment is the concatenation of the nodelists from each of its selectors in the order that the selectors appear in the list. Note: Any node matched by more than one selector is kept as many times in the nodelist.

A child segment can only contain selectors according to the RFC’s ABNF grammar, so it cannot contain another child segment, or a new expression starting with the root identifier.

Constant Summary

Constants inherited from Base

Base::NOTHING

Instance Attribute Summary

Attributes inherited from Base

#next, #node

Instance Method Summary collapse

Constructor Details

#initialize(child_segment) ⇒ ChildSegmentInterpreter

Returns a new instance of ChildSegmentInterpreter.

Parameters:



16
17
18
19
20
21
22
# File 'lib/janeway/interpreters/child_segment_interpreter.rb', line 16

def initialize(child_segment)
  super
  @nodes =
    child_segment.map do |expr|
      TreeConstructor.ast_node_to_interpreter(expr)
    end
end

Instance Method Details

#interpret(input, root) ⇒ Array

Interpret a set of 2 or more selectors, seperated by the union operator. All selectors are sent the identical input, the results are combined.

Parameters:

  • input (Array, Hash)

    the results of processing so far

  • root (Array, Hash)

    the entire input

Returns:

  • (Array)


30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/janeway/interpreters/child_segment_interpreter.rb', line 30

def interpret(input, root)
  # Apply each expression to the input, collect results
  results = []
  @nodes.each do |node|
    results.concat node.interpret(input, root)
  end

  # Return results, or forward them to the next selector
  return results unless @next

  @next.interpret(results, root)
end