Module: CSVDecision::Input

Defined in:
lib/csv_decision/input.rb

Overview

Parse the input hash.

Class Method Summary collapse

Class Method Details

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

Returns a hash of two hashes:

  • hash: either a copy with keys symbolized or the original input object

  • scan_cols: Picks out the value in the input hash for each table input column. Defaults to nil if the key is missing in the input hash.

Parameters:

  • table (CSVDecision::Table)

    Decision table.

  • input (Hash)

    Input hash (keys may or may not be symbolized)

  • symbolize_keys (true, false)

    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 => Hash{Symbol=>Object}, Hash{Integer=>Object}})

    Returns a hash of two hashes:

    • hash: either a copy with keys symbolized or the original input object

    • scan_cols: Picks out the value in the input hash for each table input column. Defaults to nil if the key is missing in the input hash.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/csv_decision/input.rb', line 15

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

  # For safety the default is to symbolize keys and make a copy of the hash.
  # However, if this is turned off then the keys must already symbolized.
  input = symbolize_keys ? input.symbolize_keys : input

  parsed_input = parse_input(table: table, input: input)

  # Freeze the copy of the input hash we just created.
  parsed_input[:hash].freeze if symbolize_keys

  parsed_input
end