Sha256: a0608f266d328ff647b2985dd59658aa8c346ba425971cd966c88744348ab6d5

Contents?: true

Size: 725 Bytes

Versions: 3

Compression:

Stored size: 725 Bytes

Contents

module CsvPiper
  module Processors
    # Collects transformed objects for use after processing.
    # Instantiate and keep a reference, then once processing complete retrieve transformed objects through #output
    class CollectOutput
      # @return[Array] Holds all of the transformed objects for each row that was processed
      # { row_index => { errors_key => array_of_error } }
      attr_reader :output
      def initialize(collect_when_invalid: true)
        @output = []
        @collect_when_invalid = collect_when_invalid
      end

      def process(_source, transformed, errors)
        @output << transformed if @collect_when_invalid || errors.empty?
        [transformed, errors]
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
csv_piper-1.0.0 lib/csv_piper/processors/collect_output.rb
csv_piper-0.1.9 lib/csv_piper/processors/collect_output.rb
csv_piper-0.1.8 lib/csv_piper/processors/collect_output.rb