Class: Janeway::Interpreters::FilterSelectorDeleter

Inherits:
FilterSelectorInterpreter show all
Defined in:
lib/janeway/interpreters/filter_selector_deleter.rb

Overview

Interprets a filter selector, and deletes matching values

Constant Summary

Constants inherited from Base

Base::NOTHING

Instance Attribute Summary

Attributes inherited from Base

#next, #node

Instance Method Summary collapse

Methods inherited from FilterSelectorInterpreter

#as_json, #initialize, #interpret, setup_interpreter_tree

Methods inherited from Base

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

Constructor Details

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

Instance Method Details

#interpret_array(input, root, _path) ⇒ Object

Interpret selector on the input.

Parameters:

  • input (Array)

    the results of processing so far

  • root (Array, Hash)

    the entire input

  • _path (Array<String>)

    elements of normalized path to the current input



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/janeway/interpreters/filter_selector_deleter.rb', line 38

def interpret_array(input, root, _path)
  # Apply filter expressions to the input data
  results = []

  # Iterate in reverse order so that deletion does not alter the remaining indexes
  i = input.size
  input.reverse_each do |value|
    i -= 1 # calculate array index

    # Run filter and interpret result
    result = @expr.interpret(value, nil, root, [])
    case result
    when TrueClass then results << value # comparison test - pass
    when FalseClass then next # comparison test - fail
    when Array
      next if result.empty?

      results << value # existence test - node list
    else
      results << value # existence test. Null values here == success.
    end
    input.delete_at(i)
  end
  results.reverse
end

#interpret_hash(input, root, _path) ⇒ Object

Interpret selector on the input.

Parameters:

  • input (Hash)

    the results of processing so far

  • root (Array, Hash)

    the entire input

  • _path (Array<String>)

    elements of normalized path to the current input



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/janeway/interpreters/filter_selector_deleter.rb', line 13

def interpret_hash(input, root, _path)
  # Apply filter expressions to the input data
  results = []
  input.each do |key, value|
    # Run filter and interpret result
    result = @expr.interpret(value, nil, root, [])
    case result
    when TrueClass then results << value # comparison test - pass
    when FalseClass then next # comparison test - fail
    when Array
      next if result.empty?

      results << value # existence test - node list
    else
      results << value # existence test. Null values here == success.
    end
    input.delete(key)
  end
  results
end