Module: CSVDecision2

Defined in:
lib/csv_decision2.rb,
lib/csv_decision2/data.rb,
lib/csv_decision2/load.rb,
lib/csv_decision2/scan.rb,
lib/csv_decision2/index.rb,
lib/csv_decision2/input.rb,
lib/csv_decision2/parse.rb,
lib/csv_decision2/paths.rb,
lib/csv_decision2/table.rb,
lib/csv_decision2/header.rb,
lib/csv_decision2/result.rb,
lib/csv_decision2/columns.rb,
lib/csv_decision2/options.rb,
lib/csv_decision2/decision.rb,
lib/csv_decision2/defaults.rb,
lib/csv_decision2/matchers.rb,
lib/csv_decision2/scan_row.rb,
lib/csv_decision2/validate.rb,
lib/csv_decision2/dictionary.rb,
lib/csv_decision2/matchers/guard.rb,
lib/csv_decision2/matchers/range.rb,
lib/csv_decision2/matchers/symbol.rb,
lib/csv_decision2/matchers/numeric.rb,
lib/csv_decision2/matchers/pattern.rb,
lib/csv_decision2/matchers/constant.rb,
lib/csv_decision2/matchers/function.rb

Overview

CSV Decision: CSV based Ruby decision tables. Created December 2017. See LICENSE and README.md for details.

Author:

Defined Under Namespace

Modules: Data, Defaults, Dictionary, Header, Input, Load, Options, Parse, Validate Classes: CellValidationError, Columns, Decision, Error, FileError, Index, Matchers, Paths, Result, Scan, ScanRow, Table, TableValidationError

Class Method Summary collapse

Class Method Details

.load(path, options = {}) ⇒ Hash{Symbol=><CSVDecision2::Table>}

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

Parameters:

  • path (Pathname)

    Directory containing CSV decision table files.

  • options (Hash{Symbol=>Object}) (defaults to: {})

    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.



15
16
17
# File 'lib/csv_decision2/load.rb', line 15

def self.load(path, options = {})
  Load.path(path: path, options: options)
end

.parse(data, options = {}) ⇒ CSVDecision2::Table

Builds a decision table from the input data - which may either be a file, CSV string or an array of arrays.

Examples:

Simple Example

If you have cloned the gem's git repo, then you can run:
table = CSVDecision2.parse(Pathname('spec/data/valid/simple_example.csv'))
  #=> CSVDecision2::Table
table.decide(topic: 'finance', region: 'Europe') #=> team_member: 'Donald'

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}) (defaults to: {})

    Options hash controlling how the table is parsed and interpreted.

Options Hash (options):

  • :first_match (Boolean)

    Stop scanning after finding the first row match.

  • :regexp_implicit (Boolean)

    Make regular expressions implicit rather than requiring the comparator =~. (Use with care.)

  • :text_only (Boolean)

    All cells treated as simple strings by turning off all special matchers.

  • :matchers (Array<Matchers::Matcher>)

    May be used to control the inclusion and ordering of special matchers. (Advanced feature, use with care.)

Returns:

Raises:



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

def self.parse(data, options = {})
  Parse.table(data: data, options: Options.normalize(options))
end

.rootString

Returns gem project’s root directory.

Returns:

  • (String)

    gem project’s root directory



12
13
14
# File 'lib/csv_decision2.rb', line 12

def self.root
  File.dirname __dir__
end