Class: CSVConverter::AttributeProcessor
- Inherits:
-
Object
- Object
- CSVConverter::AttributeProcessor
- Defined in:
- lib/csv_converter/attribute_processor.rb
Overview
Extracts the value for a column from the csv row and applies conversions to it.
Instance Attribute Summary collapse
-
#attr_mappings ⇒ Hash
readonly
Attribute mappings.
-
#data ⇒ String
readonly
The column being processed.
-
#options ⇒ Hash
readonly
Details of the data being processed.
-
#row ⇒ Array, Hash
readonly
The row being processed.
Instance Method Summary collapse
-
#call ⇒ Object
Converts the data of the attribute into the type provided in the mappings by invoking the converters.
-
#call! ⇒ Object
Converts the data of the attribute into the type provided in the mappings by invoking the converters.
-
#initialize(row, attr_mappings, options = {}) ⇒ AttributeProcessor
constructor
A new instance of AttributeProcessor.
Constructor Details
#initialize(row, attr_mappings, options = {}) ⇒ AttributeProcessor
A new instance of AttributeProcessor.
32 33 34 35 36 37 |
# File 'lib/csv_converter/attribute_processor.rb', line 32 def initialize(row, attr_mappings, = {}) @row = row @attr_mappings = attr_mappings @options = @data = row[attr_mappings[:header]] end |
Instance Attribute Details
#attr_mappings ⇒ Hash (readonly)
Attribute mappings.
16 17 18 |
# File 'lib/csv_converter/attribute_processor.rb', line 16 def attr_mappings @attr_mappings end |
#data ⇒ String (readonly)
The column being processed.
12 13 14 |
# File 'lib/csv_converter/attribute_processor.rb', line 12 def data @data 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.
26 27 28 |
# File 'lib/csv_converter/attribute_processor.rb', line 26 def @options end |
#row ⇒ Array, Hash (readonly)
The row being processed.
8 9 10 |
# File 'lib/csv_converter/attribute_processor.rb', line 8 def row @row end |
Instance Method Details
#call ⇒ Object
Converts the data of the attribute into the type provided in the mappings by invoking the converters.
42 43 44 |
# File 'lib/csv_converter/attribute_processor.rb', line 42 def call convert_attr(&:call) end |
#call! ⇒ Object
Converts the data of the attribute into the type provided in the mappings by invoking the converters.
49 50 51 |
# File 'lib/csv_converter/attribute_processor.rb', line 49 def call! convert_attr(&:call!) end |