Class: Janeway::Interpreters::Yielder

Inherits:
Object
  • Object
show all
Includes:
IterationHelper
Defined in:
lib/janeway/interpreters/yielder.rb

Overview

Yields each input value.

This is inserted at the end of the “real” selectors in the AST, to receive and yield the output. This is a supporting class for the Janeway.each method.

Instance Method Summary collapse

Methods included from IterationHelper

#make_yield_proc, #normalized_path

Constructor Details

#initialize(&block) ⇒ Yielder

Returns a new instance of Yielder.



15
16
17
18
19
20
# File 'lib/janeway/interpreters/yielder.rb', line 15

def initialize(&block)
  @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

#as_jsonHash

Returns:

  • (Hash)


41
42
43
# File 'lib/janeway/interpreters/yielder.rb', line 41

def as_json
  { type: self.class.to_s.split('::').last }
end

#interpret(input, parent, _root, path) {|matched| ... } ⇒ Object

Yield each input value

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, Integer>)

    components of normalized path to the current input

Yield Parameters:

  • matched (Object)

    value

Returns:

  • (Object)

    input as node list



30
31
32
33
# File 'lib/janeway/interpreters/yielder.rb', line 30

def interpret(input, parent, _root, path)
  @yield_proc.call(input, parent, path)
  input.is_a?(Array) ? input : [input]
end

#next=void

This method returns an undefined value.

Dummy method from Interpreters::Base, allow child segment interpreter to disable the non-exist ‘next’ link.



38
# File 'lib/janeway/interpreters/yielder.rb', line 38

def next=(*); end