Sha256: 1469bf3180024e2a5c4185a7f56fd0447c9fa33e159a4c479a4e5edad77a0804

Contents?: true

Size: 1.02 KB

Versions: 5

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

# CSV Decision: CSV based Ruby decision tables.
# Created December 2017 by Brett Vickers
# See LICENSE and README.md for details.
module CSVDecision
  # Load all the CSV files located in the designated folder path.
  #
  # @param path [Pathname] - directiory containing CSV files
  # @param options [Hash] - supplied options hash for table creation
  # @return [Hash<CSVDecision::Table>]
  def self.load(path, options = {})
    Load.path(path: path, options: options)
  end

  # Load all CSV files located in the specified folder.
  module Load
    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
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
csv_decision-0.0.6 lib/csv_decision/load.rb
csv_decision-0.0.5 lib/csv_decision/load.rb
csv_decision-0.0.4 lib/csv_decision/load.rb
csv_decision-0.0.3 lib/csv_decision/load.rb
csv_decision-0.0.2 lib/csv_decision/load.rb