Sha256: 0e00d3bd6d5fe427d49f9f974666d8e736de30cb2ab1702db4a35f67e153f38a

Contents?: true

Size: 872 Bytes

Versions: 3

Compression:

Stored size: 872 Bytes

Contents

module Itiel
  module Transform
    #
    # This transformation only selects specific columns on the data stream
    #
    # Usage:
    #
    #     @transformer = Itiel::Transform::SelectColumn.new("order_id", "name")
    #
    # In the example, the output stream would only have the order_id and the name column
    # All other columns will be ignored
    #
    class SelectColumn
      include ChainedStep
      include Itiel::Nameable

      attr_accessor :mappings

      def input=(stream)
        next_step.input = transform!(stream)
      end

      def initialize(*args)
        self.mappings = args
      end

      def transform!(input_stream)
        selected_output = []
        input_stream.each do |object|
          selected_output << object.select {|key, value| self.mappings.include? key }
        end

        selected_output
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

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