Class: Mandy::Mappers::Base

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

Direct Known Subclasses

PassThroughMapper, TransposeMapper

Constant Summary

Constants inherited from Task

Task::DEFAULT_COUNTER_GROUP, 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(opts = {}, &blk) ⇒ Object



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

def self.compile(opts={}, &blk)
  Class.new(Mandy::Mappers::Base) do 
    self.class_eval do
      define_method(:mapper, blk) if blk
      define_method(:setup, opts[:setup]) if opts[:setup]
      define_method(:teardown, opts[:teardown]) if opts[:teardown]
    end
  end
end

Instance Method Details

#executeObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/mandy/mappers/base_mapper.rb', line 16

def execute
  setup if self.respond_to?(:setup)
  @input.each_line do |line|
     key, value = line.split(KEY_VALUE_SEPERATOR, 2)
     key, value = nil, key if value.nil?
     value.chomp!
     args = [input_deserialize_key(key), input_deserialize_value(value)].compact
     mapper(*args)
  end
  teardown if self.respond_to?(:teardown)
end