Class: Mandy::Mappers::Base

Inherits:
Task
  • Object
show all
Includes:
IO::InputFormatting
Defined in:
lib/mappers/base_mapper.rb

Direct Known Subclasses

PassThroughMapper, TransposeMapper

Constant Summary

Constants inherited from Task

Task::JSON_PAYLOAD_KEY, Task::KEY_VALUE_SEPERATOR, Task::NUMERIC_PADDING

Instance Attribute Summary

Attributes inherited from Task

#input_format, #output_format

Class Method Summary collapse

Instance Method Summary collapse

Methods included from IO::InputFormatting

#input_deserialize_key, #input_deserialize_value

Methods inherited from Task

#emit, #get, #initialize, #put

Constructor Details

This class inherits a constructor from Mandy::Task

Class Method Details

.compile(&blk) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/mappers/base_mapper.rb', line 6

def self.compile(&blk)
  Class.new(Mandy::Mappers::Base) do 
    self.class_eval do
      define_method(:mapper, blk) if blk
    end
  end
end

Instance Method Details

#executeObject



14
15
16
17
18
19
20
21
# File 'lib/mappers/base_mapper.rb', line 14

def execute
  @input.each_line do |line|
     key, value = line.split(KEY_VALUE_SEPERATOR, 2)
     key, value = nil, key if value.nil?
     value.chomp!
     mapper(input_deserialize_key(key), input_deserialize_value(value))
  end
end