Class: CSVDecision::Table
- Inherits:
-
Object
- Object
- CSVDecision::Table
- Defined in:
- lib/csv_decision/table.rb
Overview
Decision Table that accepts input hashes and makes decisions
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.
-
#options ⇒ Hash
All options, explicitly set or defaulted, used to parse the table.
-
#outs_rows ⇒ Array<CSVDecision::ScanRow>
Used to implement outputting of final results.
-
#rows ⇒ Array<Array>
Data rows after parsing.
-
#scan_rows ⇒ Array<CSVDecision::ScanRow>
Scanning objects used to implement input matching logic.
Instance Method Summary collapse
-
#decide(input) ⇒ Hash{Symbol => Object, Array<Object>}
Main public method for making decisions.
-
#decide!(input) ⇒ Hash{Symbol => Object, Array<Object>}
Unsafe version of decide - will mutate the hash if set: column type is used (planned feature).
-
#each(first = 0, last = @rows.count - 1) ⇒ Object
Iterate through all data rows of the decision table, with an optional first and last row index given.
-
#initialize ⇒ Table
constructor
A new instance of Table.
Constructor Details
#initialize ⇒ Table
Returns a new instance of Table.
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/csv_decision/table.rb', line 68 def initialize @columns = nil @file = nil @matchers = [] @options = nil @outs_functions = nil @outs_rows = [] @rows = [] @scan_rows = [] @tables = nil end |
Instance Attribute Details
#columns ⇒ CSVDecision::Columns
Returns Dictionary of all input and output columns.
10 11 12 |
# File 'lib/csv_decision/table.rb', line 10 def columns @columns end |
#file ⇒ File, ...
Returns File path name if decision table was loaded from a CSV file.
13 14 15 |
# File 'lib/csv_decision/table.rb', line 13 def file @file end |
#options ⇒ Hash
Returns All options, explicitly set or defaulted, used to parse the table.
16 17 18 |
# File 'lib/csv_decision/table.rb', line 16 def @options end |
#outs_rows ⇒ Array<CSVDecision::ScanRow>
Returns Used to implement outputting of final results.
28 29 30 |
# File 'lib/csv_decision/table.rb', line 28 def outs_rows @outs_rows end |
#rows ⇒ Array<Array>
Returns Data rows after parsing.
22 23 24 |
# File 'lib/csv_decision/table.rb', line 22 def rows @rows end |
#scan_rows ⇒ Array<CSVDecision::ScanRow>
Returns Scanning objects used to implement input matching logic.
25 26 27 |
# File 'lib/csv_decision/table.rb', line 25 def scan_rows @scan_rows end |
Instance Method Details
#decide(input) ⇒ Hash{Symbol => Object, Array<Object>}
Input hash keys may or may not be symbolized.
Main public method for making decisions.
40 41 42 |
# File 'lib/csv_decision/table.rb', line 40 def decide(input) Decide.decide(table: self, input: input, symbolize_keys: true).result end |
#decide!(input) ⇒ Hash{Symbol => Object, Array<Object>}
Input hash must have its keys symbolized.
Unsafe version of decide - will mutate the hash if set: column type is used (planned feature).
50 51 52 |
# File 'lib/csv_decision/table.rb', line 50 def decide!(input) Decide.decide(table: self, input: input, symbolize_keys: false).result end |
#each(first = 0, last = @rows.count - 1) ⇒ Object
Iterate through all data rows of the decision table, with an optional first and last row index given.
59 60 61 62 63 64 65 66 |
# File 'lib/csv_decision/table.rb', line 59 def each(first = 0, last = @rows.count - 1) index = first while index <= (last || first) yield(@rows[index], index) index += 1 end end |