Class: Janeway::Interpreters::RootNodeDeleteIf

Inherits:
RootNodeInterpreter show all
Includes:
IterationHelper
Defined in:
lib/janeway/interpreters/root_node_delete_if.rb

Overview

Delete values from the root node for which the block returns a truthy value.

Constant Summary

Constants included from IterationHelper

IterationHelper::PASS_ALL

Constants inherited from Base

Base::NOTHING

Instance Attribute Summary

Attributes inherited from Base

#next, #node

Instance Method Summary collapse

Methods included from IterationHelper

#make_yield_proc, #normalized_path

Methods inherited from Base

#as_json, #selector, #to_s, #type

Constructor Details

#initialize(node, &block) ⇒ RootNodeDeleteIf

Returns a new instance of RootNodeDeleteIf.

Parameters:



13
14
15
16
17
18
19
# File 'lib/janeway/interpreters/root_node_delete_if.rb', line 13

def initialize(node, &block)
  super(node)
  @block = block

  # Make a proc that yields the correct number of values to a block
  @yield_proc = make_yield_proc(&block)
end

Instance Method Details

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

Delete values from the root container for which the block returns truthy.

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>) (defaults to: nil)

    elements of normalized path to the current input

Returns:

  • (Array)

    deleted elements



28
29
30
31
32
33
34
# File 'lib/janeway/interpreters/root_node_delete_if.rb', line 28

def interpret(_input, _parent, root, _path = nil)
  case root
  when Array then maybe_delete_array_values(root)
  when Hash then maybe_delete_hash_values(root)
  else []
  end
end