Class: CSVConverter::FileProcessor
- Inherits:
-
Object
- Object
- CSVConverter::FileProcessor
- Defined in:
- lib/csv_converter/file_processor.rb
Overview
Iterates over a collection and processes the data accordingly.
Instance Attribute Summary collapse
-
#file_mappings ⇒ Hash
readonly
File mappings.
-
#filename ⇒ String
readonly
Name of the file being processed.
-
#rows ⇒ Array
readonly
Collection being processed.
Instance Method Summary collapse
-
#call ⇒ Array
Iterates over the rows grouping and converting the data as expected based on the mappings.
-
#call! ⇒ Array
Iterates over the rows grouping and converting the data as expected based on the mappings.
-
#initialize(filename, rows, file_mappings) ⇒ FileProcessor
constructor
A new instance of FileProcessor.
Constructor Details
#initialize(filename, rows, file_mappings) ⇒ FileProcessor
A new instance of FileProcessor.
22 23 24 25 26 |
# File 'lib/csv_converter/file_processor.rb', line 22 def initialize(filename, rows, file_mappings) @filename = filename @rows = rows @file_mappings = file_mappings.with_indifferent_access end |
Instance Attribute Details
#file_mappings ⇒ Hash (readonly)
File mappings.
16 17 18 |
# File 'lib/csv_converter/file_processor.rb', line 16 def file_mappings @file_mappings end |
#filename ⇒ String (readonly)
Name of the file being processed.
8 9 10 |
# File 'lib/csv_converter/file_processor.rb', line 8 def filename @filename end |
#rows ⇒ Array (readonly)
Collection being processed.
12 13 14 |
# File 'lib/csv_converter/file_processor.rb', line 12 def rows @rows end |
Instance Method Details
#call ⇒ Array
Iterates over the rows grouping and converting the data as expected based on the mappings.
32 33 34 35 36 |
# File 'lib/csv_converter/file_processor.rb', line 32 def call rows.map.with_index do |row, row_num| process_entities(row, row_num, &:call) end end |
#call! ⇒ Array
Iterates over the rows grouping and converting the data as expected based on the mappings.
41 42 43 44 45 |
# File 'lib/csv_converter/file_processor.rb', line 41 def call! rows.map.with_index do |row, row_num| process_entities(row, row_num, &:call!) end end |