Module: CSVDecision2::Options Private

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

Validate and normalize the options values supplied.

Constant Summary collapse

DEFAULT_MATCHERS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Specialized cell value matchers beyond simple string compares. By default all these matchers are tried in the specified order on all input data cells.

[
  Matchers::Range,
  Matchers::Numeric,
  Matchers::Pattern,
  Matchers::Constant,
  Matchers::Symbol,
  Matchers::Guard
].freeze

Class Method Summary collapse

Class Method Details

.from_csv(rows:, options:) ⇒ Hash

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.

Read any options supplied in the CSV file placed before the header row.

Parameters:

  • rows (Array<Array<String>>)

    Table data rows.

  • options (Hash)

    Input options hash built so far.

Returns:

  • (Hash)

    Options hash overridden with any values found in the CSV file.



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/csv_decision2/options.rb', line 56

def self.from_csv(rows:, options:)
  row = rows.first
  return options if row.nil?

  # Have we hit the header row?
  return options if Header.row?(row)

  # Scan each cell looking for valid option values
  options = scan_cells(row: row, options: options)

  rows.shift
  from_csv(rows: rows, options: options)
end

.normalize(options) ⇒ Hash

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.

Validate options and supply default values for any options not explicitly set.

Parameters:

  • options (Hash)

    Input options hash supplied by the user.

Returns:

  • (Hash)

    Options hash filled in with all required values, defaulted if necessary.

Raises:



46
47
48
49
# File 'lib/csv_decision2/options.rb', line 46

def self.normalize(options)
  validate(options)
  default(options)
end