Class: Wukong::Processor::ToTsv

Inherits:
Serializer show all
Defined in:
lib/wukong/widget/serializers.rb

Overview

A widget for serializing inputs to TSV.

Examples:

Serializing to TSV at the end of a data flow


Wukong.dataflow(:emits_tsv) do
  ... | to_tsv
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 Serializer

#handle_error

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_stage_link, #linkable_name, #root

Instance Method Details

#process(record) {|tsv| ... } ⇒ Object

Yields the input record serialized as TSV.

Parameters:

  • record (Object)

Yields:

  • (tsv)

    the serialized TSV output

Yield Parameters:



107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/wukong/widget/serializers.rb', line 107

def process(record)
  if record.respond_to?(:to_tsv)
    tsv = record.to_tsv
  else         
    wire_format = record.try(:to_wire) || record
    raise SerializerError.new("Record must be in Array format to be serialized as TSV") unless wire_format.respond_to?(:map)
    tsv = wire_format.map(&:to_s).join("\t")
  end
  yield tsv
rescue => e
  handle_error(record, e)
end