Class: Wukong::Processor::Flatten

Inherits:
Wukong::Processor show all
Defined in:
lib/wukong/widget/operators.rb

Overview

If an input record defines the #each method then yield each of its records. Otherwise yield the input record.

Examples:

Turning one record into many


Wukong.dataflow(:authors_to_books) do
  ... | author_parser | map(&:books) | flatten | book_processor | ...
end

See Also:

Constant Summary

Constants inherited from Wukong::Processor

SerializerError

Instance Attribute Summary

Attributes included from Hanuman::StageInstanceMethods

#graph

Instance Method Summary collapse

Methods inherited from Wukong::Processor

configure, description, #finalize, #perform_action, #receive_action, #setup, #stop

Methods included from Logging

included

Methods inherited from Hanuman::Stage

#clone

Methods included from Hanuman::StageClassMethods

#builder, #label, #register, #set_builder

Methods included from Hanuman::StageInstanceMethods

#add_link, #linkable_name, #root

Instance Method Details

#process(input_record) {|output_record| ... } ⇒ Object

If input_record responds to #each then yield each of these as an output record. Else, just yield the input_record.

Parameters:

  • input_record (Object)

Yields:

  • (output_record)

Yield Parameters:

  • output_record (Object)


71
72
73
74
75
76
77
# File 'lib/wukong/widget/operators.rb', line 71

def process(input_record)
  if input_record.respond_to?(:each)
    input_record.each{ |output_record| yield(output_record) }
  else
    yield(input_record)
  end
end