Class: Wukong::Processor::Map

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

Overview

Yield the result of this processor's action for each input record.

Can also be called with the :compact option which will check if the result of the action is non falsy before yielding.

Examples:

Apply a function (like a parser) to each record


Wukong.dataflow(:parser) do
  ... |  map { |string| MyParser.parse(string) } | ...
end

Succintly map between objects


Wukong.dataflow(:converter) do
  ... | my_book_parser | map(&:author) | author_processor | ...
end

Mapping but only if it exists


Wukong.dataflow(:converter_and_trimmer) do
  ... | my_book_parser | map(compact: true, &:author) | processor_that_needs_an_author | ...
end

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

Call #perform_action on the input_record and yield the returned output record.

If #compact then only yield the output record if it is not falsy.

Parameters:

  • input_record (Object)

Yields:

  • (output_record)

    if compact, then only yield if it is not falsy

Yield Parameters:

  • output_record (Object)

    the result of #perform_action

See Also:



42
43
44
45
46
47
48
49
# File 'lib/wukong/widget/operators.rb', line 42

def process(input_record)
  output_record = perform_action(input_record)
  if compact
    yield output_record if output_record
  else
    yield output_record
  end
end