Class: CsvPiper::Processors::CollectOutput

Inherits:
Object
  • Object
show all
Defined in:
lib/csv_piper/processors/collect_output.rb

Overview

Collects transformed objects for use after processing. Instantiate and keep a reference, then once processing complete retrieve transformed objects through #output

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collect_when_invalid: true) ⇒ CollectOutput

Returns a new instance of CollectOutput.



9
10
11
12
# File 'lib/csv_piper/processors/collect_output.rb', line 9

def initialize(collect_when_invalid: true)
  @output = []
  @collect_when_invalid = collect_when_invalid
end

Instance Attribute Details

#outputObject (readonly)

@return Holds all of the transformed objects for each row that was processed { row_index => { errors_key => array_of_error } }



8
9
10
# File 'lib/csv_piper/processors/collect_output.rb', line 8

def output
  @output
end

Instance Method Details

#process(_source, transformed, errors) ⇒ Object



14
15
16
17
# File 'lib/csv_piper/processors/collect_output.rb', line 14

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