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.
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) ⇒ {Symbol=>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 ⇒ {Symbol=>Object}
private
Derive the final result.
- #initialize(table:, input:) ⇒ Object constructor
Constructor Details
#initialize(table:, input:) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/csv_decision/result.rb', line 19 def initialize(table:, input:) @outs = table.columns.outs @if_columns = table.columns.ifs # 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 = input[:hash]&.slice(*table.columns.input_keys) if table.outs_functions # Attributes hash contains the output decision key value pairs @attributes = {} # Set to true if the result has more than one row. # Only possible for the first_match: false option. @multi_result = false 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
16 17 18 |
# File 'lib/csv_decision/result.rb', line 16 def multi_result @multi_result 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.
49 50 51 |
# File 'lib/csv_decision/result.rb', line 49 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.
42 43 44 |
# File 'lib/csv_decision/result.rb', line 42 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.
82 83 84 |
# File 'lib/csv_decision/result.rb', line 82 def eval_cell_proc(proc:, column_name:, index:) @attributes[column_name][index] = proc.function[partial_result(index)] end |
#eval_outs(row) ⇒ {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.
Evaluate the output columns, and use them to start building the final result, along with the partial result required to evaluate functions.
67 68 69 70 71 72 73 74 75 |
# File 'lib/csv_decision/result.rb', line 67 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 end |
#final ⇒ {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.
55 56 57 58 59 60 |
# File 'lib/csv_decision/result.rb', line 55 def final # If there are no if: columns, then nothing needs to be filtered out of this result hash. return @attributes if @if_columns.empty? @multi_result ? multi_row_result : single_row_result end |