Module: CSVDecision::Load Private

Defined in:
lib/csv_decision/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<CSVDecision::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 files.

  • options (Hash)

    Options hash used for table creation.

Returns:

Raises:

  • (ArgumentError)

    Invalid folder.



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

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] = CSVDecision.parse(Pathname(file_name), options)
  end

  tables.freeze
end