Method: Janeway::Interpreters::IndexSelectorDeleter#interpret

Defined in:
lib/janeway/interpreters/index_selector_deleter.rb

#interpret(input, _parent, _root, _path) ⇒ Object

Interpret selector on the given input.

Parameters:

  • input (Array, Hash)

    the results of processing so far

  • _parent (Array, Hash)

    parent of the input object

  • _root (Array, Hash)

    the entire input

  • _path (Array<String>)

    elements of normalized path to the current input



14
15
16
17
18
19
20
21
22
23
# File 'lib/janeway/interpreters/index_selector_deleter.rb', line 14

def interpret(input, _parent, _root, _path)
  return [] unless input.is_a?(Array)

  index = selector.value
  result = input.fetch(index) # raises IndexError if no such index
  input.delete_at(index) # returns nil if deleted value is nil, or if no value was deleted
  [result]
rescue IndexError
  []
end