Module: CSVDecision2::Parse Private

Defined in:
lib/csv_decision2/parse.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.

Methods to parse the decision table and return CSVDecision2::Table object.

Class Method Summary collapse

Class Method Details

.table(data:, options:) ⇒ CSVDecision2::Table

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.

Parse the CSV file or input data and create a new decision table object.

Parameters:

  • data (Pathname, File, Array<Array<String>>, String)

    input data given as a CSV file, array of arrays or CSV string.

  • options (Hash{Symbol=>Object})

    Options hash controlling how the table is parsed and interpreted.

Returns:



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/csv_decision2/parse.rb', line 58

def self.table(data:, options:)
  table = CSVDecision2::Table.new

  # In most cases the decision table will be loaded from a CSV file.
  table.file = data if Data.input_file?(data)

  parse_table(table: table, input: data, options: options)

  # The table object is now immutable.
  table.columns.freeze
  table.freeze
rescue CSVDecision2::Error => exp
  raise_error(file: table.file, exception: exp)
end