Class: Cascade::RowProcessor
- Inherits:
-
Object
- Object
- Cascade::RowProcessor
- Defined in:
- lib/cascade/row_processor.rb
Constant Summary collapse
- DEFAULT_PROCESSOR =
->(value) { value&.to_s&.strip }
Instance Method Summary collapse
-
#call(row) ⇒ Hash
Iterates through object using columns values supported keys as keys for iterating, then parse it by the corresponding parser.
-
#initialize(options = {}) ⇒ RowProcessor
constructor
A new instance of RowProcessor.
Constructor Details
#initialize(options = {}) ⇒ RowProcessor
Returns a new instance of RowProcessor.
13 14 15 16 17 18 19 |
# File 'lib/cascade/row_processor.rb', line 13 def initialize( = {}) @options = @ext_presenters = [:ext_presenters].to_h @columns_matching = .fetch(:columns_matching) @use_default_presenter = .fetch(:use_default_presenter, false) @deafult_presenter = .fetch(:deafult_presenter, DEFAULT_PROCESSOR) end |
Instance Method Details
#call(row) ⇒ Hash
Iterates through object using columns values supported keys as keys for iterating, then parse it by the corresponding parser.
26 27 28 29 30 31 32 |
# File 'lib/cascade/row_processor.rb', line 26 def call(row) @columns_matching.supported_keys.inject({}) do |result, key| raw_value = row.fetch(@columns_matching.index(key)) value = receive_presenter(key).call(raw_value) result.merge(key => value) end end |