Class: Janeway::Interpreters::IndexSelectorInterpreter
- Defined in:
- lib/janeway/interpreters/index_selector_interpreter.rb
Overview
Interprets an index selector, returns results or forwards them to next selector
Filter the input by returning the array element with the given index. Return empty list if input is not an array, or if array does not contain index.
Output is an array because all selectors must return node lists, even if they only select a single element.
Direct Known Subclasses
Constant Summary
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#interpret(input, _parent, root, path) ⇒ Object
Interpret an index selector on the given input.
Methods inherited from Base
#as_json, #initialize, #to_s, #type
Constructor Details
This class inherits a constructor from Janeway::Interpreters::Base
Instance Method Details
#interpret(input, _parent, root, path) ⇒ Object
Interpret an index selector on the given input. NOTHING is selected, and it is not an error, if the index lies outside the range of the array. NOTHING is selected from a value that is not an array.
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/janeway/interpreters/index_selector_interpreter.rb', line 28 def interpret(input, _parent, root, path) return [] unless input.is_a?(Array) result = input.fetch(selector.value) # raises IndexError if no such index return [result] unless @next @next.interpret(result, input, root, path + [selector.value]) rescue IndexError [] end |