Module: CSVDecision

Defined in:
lib/csv_decision.rb,
lib/csv_decision/data.rb,
lib/csv_decision/load.rb,
lib/csv_decision/input.rb,
lib/csv_decision/parse.rb,
lib/csv_decision/table.rb,
lib/csv_decision/decide.rb,
lib/csv_decision/header.rb,
lib/csv_decision/symbol.rb,
lib/csv_decision/columns.rb,
lib/csv_decision/numeric.rb,
lib/csv_decision/options.rb,
lib/csv_decision/constant.rb,
lib/csv_decision/decision.rb,
lib/csv_decision/function.rb,
lib/csv_decision/matchers.rb,
lib/csv_decision/scan_row.rb,
lib/csv_decision/matchers/range.rb,
lib/csv_decision/matchers/symbol.rb,
lib/csv_decision/matchers/numeric.rb,
lib/csv_decision/matchers/pattern.rb,
lib/csv_decision/matchers/constant.rb,
lib/csv_decision/matchers/function.rb

Overview

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

Defined Under Namespace

Modules: Constant, Data, Decide, Function, Header, Input, Load, Numeric, Options, Parse, Symbol Classes: CellValidationError, Columns, Decision, Error, FileError, Matchers, ScanRow, Table

Constant Summary collapse

COMMENT_CHARACTER =
'#'
DEFAULT_MATCHERS =

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

[
  Matchers::Range,
  Matchers::Numeric,
  Matchers::Pattern,
  Matchers::Constant,
  Matchers::Symbol
  # Matchers::Function
].freeze
OUTS_MATCHERS =

Subset of matchers that apply to output cells

[
  Matchers::Constant
# Matchers::Function
].freeze
Proc =

Value object for a cell proc.

Value.new(:type, :function)

Class Method Summary collapse

Class Method Details

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

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

Parameters:

  • path (Pathname)
    • directiory containing CSV files

  • options (Hash) (defaults to: {})
    • supplied options hash for table creation

Returns:



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

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

.parse(data, options = {}) ⇒ CSVDecision::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 = CSVDecision.parse(Pathname('spec/data/valid/simple_example.csv')) #=> CSVDecision::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) (defaults to: {})

    Options hash supplied by the user.

Options Hash (options):

  • :first_match (Boolean)

    Stop scanning after find 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:



41
42
43
# File 'lib/csv_decision/parse.rb', line 41

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_decision.rb', line 12

def self.root
  File.dirname __dir__
end