Class: CSVConverter::EntityProcessor
- Inherits:
-
Object
- Object
- CSVConverter::EntityProcessor
- Defined in:
- lib/csv_converter/entity_processor.rb
Overview
Iterates over the columns of a row and processes the data accordingly.
Instance Attribute Summary collapse
-
#entity_mappings ⇒ Hash
readonly
Entity mappings.
-
#options ⇒ Hash
readonly
Details of the data being processed.
-
#row ⇒ Array, Hash
readonly
The row being processed.
Instance Method Summary collapse
-
#call ⇒ Hash
Iterates over the attributes of each entity converting the data into the format expected by the mappings.
-
#call! ⇒ Hash
Iterates over the attributes of each entity converting the data into the format expected by the mappings.
-
#initialize(row, entity_mappings, options = {}) ⇒ EntityProcessor
constructor
A new instance of EntityProcessor.
Constructor Details
#initialize(row, entity_mappings, options = {}) ⇒ EntityProcessor
A new instance of EntityProcessor.
28 29 30 31 32 |
# File 'lib/csv_converter/entity_processor.rb', line 28 def initialize(row, entity_mappings, = {}) @row = row @entity_mappings = entity_mappings @options = end |
Instance Attribute Details
#entity_mappings ⇒ Hash (readonly)
Entity mappings.
12 13 14 |
# File 'lib/csv_converter/entity_processor.rb', line 12 def entity_mappings @entity_mappings end |
#options ⇒ Hash (readonly)
Details of the data being processed. By default this includes:
filename: the name of the file being processed.
row_num: number of the row being processed.
entity: the name of the entity being processed as provided in the mappings.
row: the raw data of the row being processed.
attr: the name of the attribute being processed as provided in the mappings.
Additionally it will contain all the options provided to the converter in the mappings.
22 23 24 |
# File 'lib/csv_converter/entity_processor.rb', line 22 def @options end |
#row ⇒ Array, Hash (readonly)
The row being processed.
8 9 10 |
# File 'lib/csv_converter/entity_processor.rb', line 8 def row @row end |
Instance Method Details
#call ⇒ Hash
Iterates over the attributes of each entity converting the data into the format expected by the mappings.
38 39 40 |
# File 'lib/csv_converter/entity_processor.rb', line 38 def call entity_attrs(&:call) end |
#call! ⇒ Hash
Iterates over the attributes of each entity converting the data into the format expected by the mappings.
45 46 47 |
# File 'lib/csv_converter/entity_processor.rb', line 45 def call! entity_attrs(&:call!) end |