Class: Janeway::Interpreters::WildcardSelectorInterpreter

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

Overview

Interprets a wildcard selector, returns results or forwards them to next selector

Constant Summary

Constants inherited from Base

Base::NOTHING

Instance Attribute Summary

Attributes inherited from Base

#next, #node

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Janeway::Interpreters::Base

Instance Method Details

#interpret(input, root) ⇒ Object

Return values from the input. For array, return the array. For Hash, return hash values. For anything else, return empty list.

Parameters:

  • input (Array, Hash)

    the results of processing so far

  • root (Array, Hash)

    the entire input



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/janeway/interpreters/wildcard_selector_interpreter.rb', line 18

def interpret(input, root)
  values =
    case input
    when Array then input
    when Hash then input.values
    else []
    end

  return values if values.empty? # early exit, no need for further processing on empty list
  return values unless @next

  # Apply child selector to each node in the output node list
  results = []
  values.each do |value|
    results.concat @next.interpret(value, root)
  end
  results
end