class CSVDecision::Table

Decision table that accepts an input hash and outputs a decision (hash).

Attributes

columns[RW]

@return [CSVDecision::Columns] Dictionary of all input and output columns.

file[RW]

@return [File, Pathname, nil] File path name if decision table was loaded from a CSV file.

if_rows[RW]

@return [Array<CSVDecision::ScanRow>] Used to implement filtering of final results. @api private

index[RW]

@return [CSVDecision::Index] The index built on one or more input columns.

options[RW]

@return [Hash] All options, explicitly set or defaulted, used to parse the table.

outs_functions[RW]

Set if the table row has any output functions (planned feature) @api private

outs_rows[RW]

@return [Array<CSVDecision::ScanRow>] Used to implement outputting of final results. @api private

paths[RW]

@return [CSVDecision::Path] The array of paths built on one or more input columns.

rows[RW]

@return [Array<Array>] Data rows after parsing. @api private

scan_rows[RW]

@return [Array<CSVDecision::ScanRow>] Scanning objects used to implement input

matching logic.

@api private

Public Class Methods

new() click to toggle source

@api private

# File lib/csv_decision/table.rb, line 83
def initialize
  @paths = []
  @outs_rows = []
  @if_rows = []
  @rows = []
  @scan_rows = []
end

Public Instance Methods

decide(input) click to toggle source

Make a decision based off an input hash.

@note Input hash keys may or may not be symbolized. @param input [Hash] Input hash. @return [{Symbol => Object, Array<Object>}] Decision hash.

# File lib/csv_decision/table.rb, line 15
def decide(input)
  decision(input: input, symbolize_keys: true)
end
decide!(input) click to toggle source

Unsafe version of decide - may mutate the input hash and assumes the input hash is symbolized.

@param input (see decide) @note Input hash must have its keys symbolized.

Input hash will be mutated by any functions that have side effects.

@return (see decide)

# File lib/csv_decision/table.rb, line 26
def decide!(input)
  decision( input: input, symbolize_keys: false)
end
each(first = 0, last = @rows.count - 1) { |rows, index| ... } click to toggle source

Iterate through all data rows of the decision table, with an optional first and last row index given.

@param first [Integer] Start row. @param last [Integer, nil] Last row. @api private

# File lib/csv_decision/table.rb, line 73
def each(first = 0, last = @rows.count - 1)
  index = first
  while index <= last
    yield(@rows[index], index)

    index += 1
  end
end

Private Instance Methods

decision(input:, symbolize_keys:) click to toggle source
# File lib/csv_decision/table.rb, line 93
def decision(input:, symbolize_keys:)
  if columns.paths.empty?
    Decision.make(table: self, input: input, symbolize_keys: symbolize_keys)
  else
    Scan.table(table: self, input: input, symbolize_keys: symbolize_keys)
  end
end