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, ...
File path name if decision table was loaded from a CSV file.
-
#if_rows ⇒ Array<CSVDecision::ScanRow>
private
Used to implement filtering of final results.
-
#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.
-
#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
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/csv_decision/table.rb', line 76 def initialize @columns = nil @file = nil @options = nil @outs_functions = nil @outs_rows = [] @if_rows = [] @rows = [] @scan_rows = [] # @tables = nil 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, ...
Returns File path name if decision table was loaded from a CSV file.
34 35 36 |
# File 'lib/csv_decision/table.rb', line 34 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.
58 59 60 |
# File 'lib/csv_decision/table.rb', line 58 def if_rows @if_rows end |
#options ⇒ Hash
Returns All options, explicitly set or defaulted, used to parse the table.
37 38 39 |
# File 'lib/csv_decision/table.rb', line 37 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)
41 42 43 |
# File 'lib/csv_decision/table.rb', line 41 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.
54 55 56 |
# File 'lib/csv_decision/table.rb', line 54 def outs_rows @outs_rows 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.
45 46 47 |
# File 'lib/csv_decision/table.rb', line 45 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.
50 51 52 |
# File 'lib/csv_decision/table.rb', line 50 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) Decide.decide(table: self, 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) Decide.decide(table: self, 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.
66 67 68 69 70 71 72 73 |
# File 'lib/csv_decision/table.rb', line 66 def each(first = 0, last = @rows.count - 1) index = first while index <= (last || first) yield(@rows[index], index) index += 1 end end |