Class: CSVDecision::Result Private
- Inherits:
-
Object
- Object
- CSVDecision::Result
- Defined in:
- lib/csv_decision/result.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) into a result hash.
Instance Attribute Summary collapse
-
#attributes ⇒ Hash{Symbol=>Object}, Hash{Integer=>Object}
readonly
private
The decision result hash containing both result values and if: columns, which eventually get evaluated and removed.
-
#multi_result ⇒ Boolean
readonly
private
Returns true if this is a multi-row result.
-
#outs ⇒ Hash{Index=>Dictionary::Entry}
readonly
private
Output columns.
-
#outs_functions ⇒ nil, true
readonly
private
Set to true if the table has output functions.
Instance Method Summary collapse
-
#accumulate_outs(row) ⇒ void
private
Accumulate the outs into arrays of values.
-
#add_outs(row) ⇒ void
private
Common case for building a single row result is just copying output column values to the final result hash.
-
#eval_cell_proc(proc:, column_name:, index:) ⇒ Object
private
Evaluate the cell proc using the partial result calculated so far.
-
#eval_outs(row) ⇒ Object
private
Evaluate the output columns, and use them to start building the final result, along with the partial result required to evaluate functions.
-
#final_result ⇒ Hash{Symbol=>Object}
private
Derive the final result.
- #initialize(table:) ⇒ Object constructor
-
#input(data) ⇒ void
private
Initialize the object for new input data.
Constructor Details
#initialize(table:) ⇒ Object
25 26 27 28 29 |
# File 'lib/csv_decision/result.rb', line 25 def initialize(table:) @outs = table.columns.outs @outs_functions = table.outs_functions @table = table end |
Instance Attribute Details
#attributes ⇒ Hash{Symbol=>Object}, Hash{Integer=>Object} (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 The decision result hash containing both result values and if: columns, which eventually get evaluated and removed.
13 14 15 |
# File 'lib/csv_decision/result.rb', line 13 def attributes @attributes end |
#multi_result ⇒ 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 this is a multi-row result
22 23 24 |
# File 'lib/csv_decision/result.rb', line 22 def multi_result @multi_result end |
#outs ⇒ Hash{Index=>Dictionary::Entry} (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 Output columns.
16 17 18 |
# File 'lib/csv_decision/result.rb', line 16 def outs @outs end |
#outs_functions ⇒ nil, true (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 Set to true if the table has output functions.
19 20 21 |
# File 'lib/csv_decision/result.rb', line 19 def outs_functions @outs_functions end |
Instance Method Details
#accumulate_outs(row) ⇒ 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.
Accumulate the outs into arrays of values.
58 59 60 |
# File 'lib/csv_decision/result.rb', line 58 def accumulate_outs(row) @outs.each_pair { |col, column| add_cell(column_name: column.name, cell: row[col]) } end |
#add_outs(row) ⇒ 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.
Common case for building a single row result is just copying output column values to the final result hash.
51 52 53 |
# File 'lib/csv_decision/result.rb', line 51 def add_outs(row) @outs.each_pair { |col, column| @attributes[column.name] = row[col] } end |
#eval_cell_proc(proc:, column_name:, index:) ⇒ 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.
Evaluate the cell proc using the partial result calculated so far.
91 92 93 |
# File 'lib/csv_decision/result.rb', line 91 def eval_cell_proc(proc:, column_name:, index:) @attributes[column_name][index] = proc.function[partial_result(index)] end |
#eval_outs(row) ⇒ 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.
Evaluate the output columns, and use them to start building the final result, along with the partial result required to evaluate functions.
76 77 78 79 80 81 82 83 84 |
# File 'lib/csv_decision/result.rb', line 76 def eval_outs(row) # Set the constants first, in case the functions refer to them eval_outs_constants(row: row) # Then evaluate the procs, left to right eval_outs_procs(row: row) final_result end |
#final_result ⇒ 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.
Derive the final result.
64 65 66 67 68 69 |
# File 'lib/csv_decision/result.rb', line 64 def final_result # If there are no if: columns, then nothing needs to be filtered out of this result hash. return @attributes if @table.columns.ifs.empty? @multi_result ? multi_row_result : single_row_result 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 object for new input data.
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/csv_decision/result.rb', line 35 def input(data) # Attributes hash contains the output decision key value pairs @attributes = {} @multi_result = false # Partial result always copies in the input hash for calculating output functions. # Note that these input key values will not be mutated, as output columns can never # have the same symbol as an input hash key. # However, the rest of this hash is mutated as output column evaluation results # are accumulated. @partial_result = data.slice(*@table.columns.input_keys) if @outs_functions end |