Class: Janeway::Interpreters::Yielder
- Inherits:
-
Object
- Object
- Janeway::Interpreters::Yielder
- 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
- #as_json ⇒ Hash
-
#initialize(&block) ⇒ Yielder
constructor
A new instance of Yielder.
-
#interpret(input, parent, _root, path) {|matched| ... } ⇒ Object
Yield each input value.
-
#next= ⇒ void
Dummy method from Interpreters::Base, allow child segment interpreter to disable the non-exist ‘next’ link.
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_json ⇒ 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
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 |