Class: SmartCsvImport::FailedRowExporter

Inherits:
Object
  • Object
show all
Defined in:
lib/smart_csv_import/failed_row_exporter.rb

Instance Method Summary collapse

Constructor Details

#initialize(csv_path:, result: nil, import: nil) ⇒ FailedRowExporter

Returns a new instance of FailedRowExporter.

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
14
15
16
17
# File 'lib/smart_csv_import/failed_row_exporter.rb', line 7

def initialize(csv_path:, result: nil, import: nil)
  raise ArgumentError, "provide either result: or import:" if result.nil? && import.nil?
  raise ArgumentError, "provide only one of result: or import:" if result && import

  @csv_path = csv_path
  @failed_lines = if result
                    (result)
                  else
                    (import)
                  end
end

Instance Method Details

#callObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/smart_csv_import/failed_row_exporter.rb', line 19

def call
  return nil if @failed_lines.empty?

  original_headers = read_original_headers
  output_path = generate_output_path

  write_failed_rows(original_headers, @failed_lines, output_path)

  output_path
end