Sha256: a2dba652949cc5dcff2efec5d8febafbbe976452726d60704382e3cd092a8253
Contents?: true
Size: 995 Bytes
Versions: 3
Compression:
Stored size: 995 Bytes
Contents
module Itiel module Transform # # Maps a field value to different values # # Usage: # # @transformation = Itiel::Transform::MapValues.new( # { # "active" => { true => "yes", false => "no" } # } # ) # # This would map all the values on the active column, true to yes and false to no # class MapValues include ChainedStep include Nameable attr_accessor :mapping def initialize(mapping) self.mapping = mapping end 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 end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
itiel-0.1.2 | lib/itiel/transform/map_values.rb |
itiel-0.1.1 | lib/itiel/transform/map_values.rb |
itiel-0.1.0 | lib/itiel/transform/map_values.rb |