Class: Janeway::Interpreters::ArraySliceSelectorInterpreter
- Defined in:
- lib/janeway/interpreters/array_slice_selector_interpreter.rb
Overview
Interprets array slice selector on the given input
Direct Known Subclasses
Constant Summary
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #as_json ⇒ Hash
-
#interpret(input, _parent, root, path) ⇒ Array
Filter the input by applying the array slice selector.
Methods inherited from Base
Constructor Details
This class inherits a constructor from Janeway::Interpreters::Base
Instance Method Details
#as_json ⇒ Hash
34 35 36 |
# File 'lib/janeway/interpreters/array_slice_selector_interpreter.rb', line 34 def as_json { type: type, value: node.to_s, next: @next&.as_json }.compact end |
#interpret(input, _parent, root, path) ⇒ Array
Filter the input by applying the array slice selector.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/janeway/interpreters/array_slice_selector_interpreter.rb', line 18 def interpret(input, _parent, root, path) return [] unless input.is_a?(Array) return [] if effective_step.zero? # RFC: When step is 0, no elements are selected. indexes = index_range(input.size) return indexes.map { |i| input[i] } unless @next # Apply child selector to each node in the output node list results = [] indexes.each do |i| results.concat @next.interpret(input[i], input, root, path + [i]) end results end |