Class: CSVDecision::Decision Private

Inherits:
Object
  • Object
show all
Defined in:
lib/csv_decision/decision.rb

Overview

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

Accumulate the matching row(s) and calculate the final result.

Instance Method Summary collapse

Constructor Details

#initialize(table:, input:) ⇒ Decision

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.

Returns a new instance of Decision.

Parameters:

  • table (CSVDecision::Table)

    Decision table being processed.

  • input (Hash{Symbol=>Object})

    Input hash data structure.



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/csv_decision/decision.rb', line 13

def initialize(table:, input:)
  # The result object is a hash of values, and each value will be an array if this is
  # a multi-row result for the +first_match: false+ option.
  @result = Result.new(table: table, input: input)

  # All rows picked by the matching process. An array if +first_match: false+, otherwise
  # a single row.
  @rows_picked = []

  # Relevant table attributes
  table_attributes(table)
end

Instance Method Details

#scan(table:, input:) ⇒ {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.

Scan the decision table up against the input hash.

Parameters:

  • table (CSVDecision::Table)

    Decision table being processed.

  • input (Hash{Symbol=>Object})

    Input hash data structure.

Returns:

  • ({Symbol=>Object})

    Decision result.



30
31
32
33
34
35
36
37
# File 'lib/csv_decision/decision.rb', line 30

def scan(table:, input:)
  table.each do |row, index|
    # +row_scan+ returns false if more rows need to be scanned, truthy otherwise.
    return result if row_scan(input: input, row: row, scan_row: table.scan_rows[index])
  end

  result
end