Class: Janeway::Interpreters::Yielder

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

Overview

Yields each input value. It 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 supports the Janeway.each method.

This will get pushed onto the end of the query AST. Currently it must act like both an AST node and an interpreter. This will be simpler if TODO some day may the interpreter subclass methods can be merged into the AST classes

Constant Summary

Constants inherited from Base

Base::NOTHING

Instance Attribute Summary

Attributes inherited from Base

#next, #node

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Yielder

The implicit constructor forwards a closure to the base class constructor. Base class constructor stores it in @node.



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

def initialize(&block)
  super(Struct.new(:next).new)
  @block = block
end

Instance Method Details

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

Yield each input value

Parameters:

  • input (Array, Hash)

    the results of processing so far

  • _root (Array, Hash)

    the entire input

Yield Parameters:

  • matched (Object)

    value

Returns:

  • (Object)

    input



28
29
30
31
# File 'lib/janeway/interpreters/yielder.rb', line 28

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