Sha256: cc6065427bb4f75eb4b06e8d8bf641fdec93608f730d0f19a5f5867737e21f48

Contents?: true

Size: 866 Bytes

Versions: 3

Compression:

Stored size: 866 Bytes

Contents

module Itiel
  module Transform
    #
    # This transformation appends a new Column
    # with a constant value to the data stream
    #
    #     Itiel::Transform::ConstantColumn.new( "column" => "Constant Value")
    #
    # Or, specify the column and the value later:
    #
    #     transformation = Itiel::Transform::ConstantColumn.new
    #
    #     transformation.append = { "column" => "Constant Value" }
    #
  	# The resulting stream will have a column named "column" with the value
  	# "Constant Value" for all rows.
  	#
    class ConstantColumn
      include ChainedStep
      include Itiel::Nameable

      attr_accessor :append

      def initialize(*args)
        self.append = args.first
      end

      def transform!(input_stream)
        input_stream.collect do |row|
          row.merge(self.append)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
itiel-0.1.2 lib/itiel/transform/constant_column.rb
itiel-0.1.1 lib/itiel/transform/constant_column.rb
itiel-0.1.0 lib/itiel/transform/constant_column.rb