Class: Janeway::Interpreters::RootNodeDeleter

Inherits:
RootNodeInterpreter show all
Defined in:
lib/janeway/interpreters/root_node_deleter.rb,
lib/janeway/interpreters/root_node_delete_if.rb

Overview

Interprets the root node for deletion

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

#as_json, #initialize, #selector, #to_s, #type

Constructor Details

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

Instance Method Details

#interpret(_input, _parent, root, _path) ⇒ Array

Delete all values from the root node.

TODO: unclear, for deletion is there a difference between queries ‘$’ and ‘$.*’?

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

Returns:

  • (Array)

    deleted elements



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

def interpret(_input, _parent, root, _path)
  case root
  when Array
    results = root.dup
    root.clear
    results
  when Hash
    results = root.values
    root.clear
    results
  else
    []
  end
end