lib/csv_piper/piper.rb in csv_piper-0.1.7 vs lib/csv_piper/piper.rb in csv_piper-0.1.8
- old
+ new
@@ -1,6 +1,9 @@
module CsvPiper
+ ###
+ # Catch exceptions on a per processor/row basis (allow other rows to continue processing)?
+ ###
class Piper
HEADER_LINE_INDEX = 1
FIRST_DATA_LINE_INDEX = 2
CSV_HEADER_OPTIONS = { headers: true, return_headers: true, skip_blanks: true, skip_lines: /^(\s*,)*$/ }
@@ -35,26 +38,26 @@
attr_reader :io, :pre_processors, :processors, :required_headers, :csv_options
def process_csv_body
csv.each.with_index(FIRST_DATA_LINE_INDEX) do |row, index|
- processed_data, row_errors = process_row(row.to_hash, Errors::Row.new(index))
+ process_row(row.to_hash, Errors::Row.new(index))
end
end
def process_row(row, row_errors)
pre_processed_row, row_errors = pre_processors.reduce([row, row_errors]) do |memo, processor|
output = processor.process(*memo)
- return if output.nil?
+ return nil if output.nil?
output
end
frozen_row = pre_processed_row.freeze
processed_data = {}
- processed_data, row_errors = processors.reduce([processed_data, row_errors]) do |memo, processor|
+ processors.reduce([processed_data, row_errors]) do |memo, processor|
output = processor.process(frozen_row, *memo)
- return if output.nil?
+ return nil if output.nil?
output
end
end
def csv