Sha256: e9fa2533dbd78bc5be9f09fcb68e65131a4d83f38c166127a35902350b3c2dcf

Contents?: true

Size: 891 Bytes

Versions: 2

Compression:

Stored size: 891 Bytes

Contents

module DataForge
  module Transformation
    class RubyTransformation < TransformationBase

      class << self
        def from_input(source_name, options = {}, &block)
          reader = File.reader_for source_name
          writers = Array(options.fetch :into, source_name).map { |target_name| File.writer_for target_name }

          new reader, writers, &block
        end
      end



      def initialize(record_reader, record_writers, &transformation_block)
        @record_reader, @record_writers, @transformation_block = record_reader, record_writers, transformation_block
      end



      def execute
        with_writers @record_writers do |writers|
          context = RubyTransformationContext.new writers
          @record_reader.each_record do |record|
            context.instance_exec record, &@transformation_block
          end
        end
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
data_forge-0.1.1 lib/data_forge/transformation/ruby_transformation.rb
data_forge-0.1 lib/data_forge/transformation/ruby_transformation.rb