class Cascade::RowProcessor
Constants
- DEFAULT_PROCESSOR
Attributes
options[R]
Public Class Methods
new(options = {})
click to toggle source
# File lib/cascade/row_processor.rb, line 13 def initialize(options = {}) @options = options @ext_presenters = options[:ext_presenters].to_h @columns_matching = options.fetch(:columns_matching) @use_default_presenter = options.fetch(:use_default_presenter, false) @deafult_presenter = options.fetch(:deafult_presenter, DEFAULT_PROCESSOR) end
Public Instance Methods
call(row)
click to toggle source
Iterates through object using columns values supported keys as keys for iterating, then parse it by the corresponding parser.
@param row [Hash] the object retrieved from data parser @return [Hash] the object with parsed columns
# 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
Private Instance Methods
predefined_presenters()
click to toggle source
# File lib/cascade/row_processor.rb, line 55 def predefined_presenters { string: DEFAULT_PROCESSOR, currency: ComplexFields::Currency.new, boolean: ComplexFields::Boolean.new, iterable_recursive: ComplexFields::ArrayProcessor.new(self_copy), recursive: self_copy } end
presenters()
click to toggle source
# File lib/cascade/row_processor.rb, line 47 def presenters @presenters ||= @ext_presenters.reverse_merge(predefined_presenters) end
receive_presenter(column_name)
click to toggle source
# File lib/cascade/row_processor.rb, line 38 def receive_presenter(column_name) presenter = presenters[@columns_matching.column_type(column_name)] if presenter.nil? && !@use_default_presenter raise Cascade::UnknownPresenterType end presenter || @deafult_presenter end
self_copy()
click to toggle source
# File lib/cascade/row_processor.rb, line 51 def self_copy self.class.new(options) end