Class: Itiel::Transform::MapValues
- Inherits:
-
Object
- Object
- Itiel::Transform::MapValues
- Includes:
- Nameable, ChainedStep
- Defined in:
- lib/itiel/transform/map_values.rb
Overview
Instance Attribute Summary collapse
-
#mapping ⇒ Object
Returns the value of attribute mapping.
Attributes included from Nameable
Attributes included from ChainedStep
Instance Method Summary collapse
-
#initialize(mapping) ⇒ MapValues
constructor
A new instance of MapValues.
- #transform!(input_stream) ⇒ Object
Methods included from ChainedStep
Constructor Details
#initialize(mapping) ⇒ MapValues
Returns a new instance of MapValues.
22 23 24 |
# File 'lib/itiel/transform/map_values.rb', line 22 def initialize(mapping) self.mapping = mapping end |
Instance Attribute Details
#mapping ⇒ Object
Returns the value of attribute mapping.
20 21 22 |
# File 'lib/itiel/transform/map_values.rb', line 20 def mapping @mapping end |
Instance Method Details
#transform!(input_stream) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/itiel/transform/map_values.rb', line 26 def transform!(input_stream) output = [] input_stream.each do |stream_row| new_row = {} stream_row.each do |column, value| if self.mapping.keys.include?(column) new_row[column] = self.mapping[column][value] || value else new_row[column] = value end end output << new_row end output end |