Class: Janeway::Interpreters::NameSelectorInterpreter

Inherits:
Base
  • Object
show all
Defined in:
lib/janeway/interpreters/name_selector_interpreter.rb

Overview

Interprets a name selector, returns results or forwards them to next selector

Filters the input by returning the key that has the given name.

Must differentiate between a null value of a key that exists (nil) and a key that does not exist ([])

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

#initialize

Constructor Details

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

Instance Method Details

#interpret(input, root) ⇒ Object

Interpret selector on the given input.

Parameters:

  • input (Array, Hash)

    the results of processing so far

  • root (Array, Hash)

    the entire input



19
20
21
22
23
24
25
26
27
# File 'lib/janeway/interpreters/name_selector_interpreter.rb', line 19

def interpret(input, root)
  return [] unless input.is_a?(Hash) && input.key?(selector.name)

  result = input[selector.name]
  return [result] unless @next

  # Forward result to next selector
  @next.interpret(result, root)
end