Module: CSVDecision2::Load Private

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

Load all CSV files located in the specified folder.

Class Method Summary collapse

Class Method Details

.path(path:, options:) ⇒ Hash{Symbol=><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.

Load all the CSV files located in the designated folder path.

Parameters:

  • path (Pathname)

    Directory containing CSV decision table files.

  • options (Hash{Symbol=>Object})

    Options hash controlling how the table is parsed and interpreted.

Returns:

  • (Hash{Symbol=><CSVDecision2::Table>})

    Hash of decision tables keyed by the CSV file’s symbolized base name.

Raises:

  • (ArgumentError)

    Invalid path name or folder.



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/csv_decision2/load.rb', line 23

def self.path(path:, options:)
  raise ArgumentError, 'path argument must be a Pathname' unless path.is_a?(Pathname)
  raise ArgumentError, 'path argument not a valid folder' unless path.directory?

  tables = {}
  Dir[path.join('*.csv')].each do |file_name|
    table_name = File.basename(file_name, '.csv').to_sym
    tables[table_name] = CSVDecision2.parse(Pathname(file_name), options)
  end

  tables.freeze
end