Class: CSVDecision::Table
- Inherits:
-
Object
- Object
- CSVDecision::Table
- Defined in:
- lib/csv_decision/table.rb
Overview
Decision table that accepts an input hash and outputs a decision (hash).
Instance Attribute Summary collapse
-
#columns ⇒ CSVDecision::Columns
Dictionary of all input and output columns.
-
#file ⇒ File, ...
CSV file.
-
#if_rows ⇒ Array<CSVDecision::ScanRow>
private
Used to implement filtering of final results.
-
#index ⇒ CSVDecision::Index
The index built on one or more input columns.
-
#options ⇒ Hash
All options, explicitly set or defaulted, used to parse the table.
-
#outs_functions ⇒ Object
private
Set if the table row has any output functions (planned feature).
-
#outs_rows ⇒ Array<CSVDecision::ScanRow>
private
Used to implement outputting of final results.
-
#paths ⇒ CSVDecision::Path
The array of paths built on one or more input columns.
-
#rows ⇒ Array<Array>
private
Data rows after parsing.
-
#scan_rows ⇒ Array<CSVDecision::ScanRow>
private
Scanning objects used to implement input matching logic.
Instance Method Summary collapse
-
#decide(input) ⇒ {Symbol => Object, Array<Object>}
Make a decision based off an input hash.
-
#decide!(input) ⇒ {Symbol => Object, Array<Object>}
Unsafe version of decide - may mutate the input hash and assumes the input hash is symbolized.
-
#each(first = 0, last = @rows.count - 1) ⇒ Object
private
Iterate through all data rows of the decision table, with an optional first and last row index given.
-
#initialize ⇒ Table
constructor
private
A new instance of Table.
Constructor Details
#initialize ⇒ 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.
Returns a new instance of Table.
83 84 85 86 87 88 89 |
# File 'lib/csv_decision/table.rb', line 83 def initialize @paths = [] @outs_rows = [] @if_rows = [] @rows = [] @scan_rows = [] end |
Instance Attribute Details
#columns ⇒ CSVDecision::Columns
Returns Dictionary of all input and output columns.
31 32 33 |
# File 'lib/csv_decision/table.rb', line 31 def columns @columns end |
#file ⇒ File, ...
CSV file.
35 36 37 |
# File 'lib/csv_decision/table.rb', line 35 def file @file end |
#if_rows ⇒ Array<CSVDecision::ScanRow>
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.
Returns Used to implement filtering of final results.
65 66 67 |
# File 'lib/csv_decision/table.rb', line 65 def if_rows @if_rows end |
#index ⇒ CSVDecision::Index
Returns The index built on one or more input columns.
38 39 40 |
# File 'lib/csv_decision/table.rb', line 38 def index @index end |
#options ⇒ Hash
Returns All options, explicitly set or defaulted, used to parse the table.
44 45 46 |
# File 'lib/csv_decision/table.rb', line 44 def @options end |
#outs_functions ⇒ Object
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.
Set if the table row has any output functions (planned feature)
48 49 50 |
# File 'lib/csv_decision/table.rb', line 48 def outs_functions @outs_functions end |
#outs_rows ⇒ Array<CSVDecision::ScanRow>
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.
Returns Used to implement outputting of final results.
61 62 63 |
# File 'lib/csv_decision/table.rb', line 61 def outs_rows @outs_rows end |
#paths ⇒ CSVDecision::Path
Returns The array of paths built on one or more input columns.
41 42 43 |
# File 'lib/csv_decision/table.rb', line 41 def paths @paths end |
#rows ⇒ Array<Array>
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.
Returns Data rows after parsing.
52 53 54 |
# File 'lib/csv_decision/table.rb', line 52 def rows @rows end |
#scan_rows ⇒ Array<CSVDecision::ScanRow>
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.
Returns Scanning objects used to implement input matching logic.
57 58 59 |
# File 'lib/csv_decision/table.rb', line 57 def scan_rows @scan_rows end |
Instance Method Details
#decide(input) ⇒ {Symbol => Object, Array<Object>}
Input hash keys may or may not be symbolized.
Make a decision based off an input hash.
15 16 17 |
# File 'lib/csv_decision/table.rb', line 15 def decide(input) decision(input: input, symbolize_keys: true) end |
#decide!(input) ⇒ {Symbol => Object, Array<Object>}
Input hash must have its keys symbolized. Input hash will be mutated by any functions that have side effects.
Unsafe version of decide - may mutate the input hash and assumes the input hash is symbolized.
26 27 28 |
# File 'lib/csv_decision/table.rb', line 26 def decide!(input) decision( input: input, symbolize_keys: false) end |
#each(first = 0, last = @rows.count - 1) ⇒ Object
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.
Iterate through all data rows of the decision table, with an optional first and last row index given.
73 74 75 76 77 78 79 80 |
# File 'lib/csv_decision/table.rb', line 73 def each(first = 0, last = @rows.count - 1) index = first while index <= last yield(@rows[index], index) index += 1 end end |