Module: CSVDecision::Input Private

Defined in:
lib/csv_decision/input.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Parse the input hash.

Class Method Summary collapse

Class Method Details

.parse(table:, input:, symbolize_keys:) ⇒ Hash{Symbol=>Object}

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • table (CSVDecision::Table)

    Decision table.

  • input (Hash)

    Input hash (keys may or may not be symbolized)

  • symbolize_keys (Boolean)

    Set to false if keys are symbolized and it’s OK to mutate the input hash. Otherwise a copy of the input hash is symbolized.

Returns:

  • (Hash{Symbol=>Object})


13
14
15
16
17
18
19
20
21
# File 'lib/csv_decision/input.rb', line 13

def self.parse(table:, input:, symbolize_keys:)
  validate(input)

  parsed_input =
    parse_data(table: table, input: symbolize_keys ? input.symbolize_keys : input)

  parsed_input[:key] = parse_key(table: table, hash: parsed_input[:hash]) if table.index
  parsed_input
end

.parse_data(table:, input:) ⇒ Hash{Symbol=>Object}

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • table (CSVDecision::Table)

    Decision table.

  • input (Hash)

    Input hash (keys may or may not be symbolized)

Returns:

  • (Hash{Symbol=>Object})


26
27
28
29
30
31
32
33
# File 'lib/csv_decision/input.rb', line 26

def self.parse_data(table:, input:)
  defaulted_columns = table.columns.defaults

  # Code path optimized for no defaults
  return parse_cells(table: table, input: input) if defaulted_columns.empty?

  parse_defaulted(table: table, input: input, defaulted_columns: defaulted_columns)
end