Class: CSVDecision::Decision Private
- Inherits:
-
Object
- Object
- CSVDecision::Decision
- Defined in:
- lib/csv_decision/decision.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Accumulate the matching row(s) and calculate the final result.
Instance Attribute Summary collapse
-
#first_match ⇒ Boolean
readonly
private
True if a first match decision table.
-
#table ⇒ CSVDecision::Table
readonly
private
Decision table object.
Class Method Summary collapse
-
.make(table:, input:, symbolize_keys:) ⇒ Hash{Symbol=>Object}
private
Main method for making decisions without a path.
Instance Method Summary collapse
-
#index_scan_accumulate(scan_cols:, hash:, index_rows:) ⇒ Hash{Symbol=>Object}
private
Scan the index for an accumulated result.
-
#index_scan_first_match(scan_cols:, hash:, index_rows:) ⇒ Hash{Symbol=>Object}
private
Scan the index for a first match result.
-
#initialize(table:) ⇒ Decision
constructor
private
A new instance of Decision.
-
#input(data) ⇒ void
private
Initialize the input data used to make the decision.
-
#scan(data) ⇒ Hash{Symbol=>Object}
private
Scan the decision table and produce an output decision.
Constructor Details
#initialize(table:) ⇒ Decision
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 Decision.
34 35 36 37 38 39 40 |
# File 'lib/csv_decision/decision.rb', line 34 def initialize(table:) # The result object is a hash of values, and each value will be an array if this is # a multi-row result for the +first_match: false+ option. @result = Result.new(table: table) @first_match = table.[:first_match] @table = table end |
Instance Attribute Details
#first_match ⇒ Boolean (readonly)
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 True if a first match decision table.
28 29 30 |
# File 'lib/csv_decision/decision.rb', line 28 def first_match @first_match end |
#table ⇒ CSVDecision::Table (readonly)
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 Decision table object.
31 32 33 |
# File 'lib/csv_decision/decision.rb', line 31 def table @table end |
Class Method Details
.make(table:, input:, symbolize_keys:) ⇒ Hash{Symbol=>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.
Main method for making decisions without a path.
18 19 20 21 22 23 24 25 |
# File 'lib/csv_decision/decision.rb', line 18 def self.make(table:, input:, symbolize_keys:) # Parse and transform the hash supplied as input data = Input.parse(table: table, input: input, symbolize_keys: symbolize_keys) # The decision object collects the results of the search and # calculates the final result. Decision.new(table: table).scan(data) end |
Instance Method Details
#index_scan_accumulate(scan_cols:, hash:, index_rows:) ⇒ Hash{Symbol=>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.
Scan the index for an accumulated result.
90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/csv_decision/decision.rb', line 90 def index_scan_accumulate(scan_cols:, hash:, index_rows:) index_rows.each do |start_row, end_row| @table.each(start_row, end_row || start_row) do |row, index| next unless @table.scan_rows[index].match?(row: row, hash: hash, scan_cols: scan_cols) # Accumulate output rows. @rows_picked << row @result.accumulate_outs(row) end end @rows_picked.empty? ? {} : accumulated_result end |
#index_scan_first_match(scan_cols:, hash:, index_rows:) ⇒ Hash{Symbol=>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.
Scan the index for a first match result.
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/csv_decision/decision.rb', line 72 def index_scan_first_match(scan_cols:, hash:, index_rows:) index_rows.each do |start_row, end_row| @table.each(start_row, end_row || start_row) do |row, index| next unless @table.scan_rows[index].match?(row: row, hash: hash, scan_cols: scan_cols) return @result.attributes if first_match_found(row) end end {} end |
#input(data) ⇒ void
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.
This method returns an undefined value.
Initialize the input data used to make the decision.
46 47 48 49 50 51 52 53 54 |
# File 'lib/csv_decision/decision.rb', line 46 def input(data) @result.input(data[:hash]) # All rows picked by the matching process. An array if +first_match: false+, # otherwise a single row. @rows_picked = [] @input = data end |
#scan(data) ⇒ Hash{Symbol=>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.
Scan the decision table and produce an output decision.
60 61 62 63 64 |
# File 'lib/csv_decision/decision.rb', line 60 def scan(data) input(data) # Use the table's index if present @table.index ? index_scan : table_scan end |