Class: Janeway::Interpreters::WildcardSelectorInterpreter
- 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
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#interpret(input, root) ⇒ Object
Return values from the input.
Methods inherited from Base
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.
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 |