Class: Cascade::RowProcessor

Inherits:
Object
  • Object
show all
Extended by:
Configuration
Defined in:
lib/cascade/row_processor.rb

Constant Summary collapse

DEFAULT_PROCESSOR =
->(value) { value }

Instance Method Summary collapse

Methods included from Configuration

configuration, define_setting

Constructor Details

#initialize(options = {}) ⇒ RowProcessor

Returns a new instance of RowProcessor.



16
17
18
19
# File 'lib/cascade/row_processor.rb', line 16

def initialize(options = {})
  @options          = options
  @columns_matching = options[:columns_matching] || ColumnsMatching.new
end

Instance Method Details

#call(row) ⇒ Hash

Iterates through object using columns values supported keys as keys for iterating, then parse it by curresponding parser.

Parameters:

  • row (Hash)

    the object retrieved from CSV

Returns:

  • (Hash)

    the object with parsed columns



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