Class: Kiba::Extend::Transforms::Count::MatchingRowsInLookup
- Inherits:
-
Object
- Object
- Kiba::Extend::Transforms::Count::MatchingRowsInLookup
- Defined in:
- lib/kiba/extend/transforms/count/matching_rows_in_lookup.rb
Overview
Merges count of lookup rows to be merged into specified field. By default it retuns the count as a string, since many of the other transforms assume string values
Instance Method Summary collapse
-
#initialize(lookup:, keycolumn:, targetfield:, conditions: {}, result_type: :str) ⇒ MatchingRowsInLookup
constructor
A new instance of MatchingRowsInLookup.
-
#process(row) ⇒ Object
Constructor Details
#initialize(lookup:, keycolumn:, targetfield:, conditions: {}, result_type: :str) ⇒ MatchingRowsInLookup
Returns a new instance of MatchingRowsInLookup.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/kiba/extend/transforms/count/matching_rows_in_lookup.rb', line 19 def initialize(lookup:, keycolumn:, targetfield:, conditions: {}, result_type: :str) @lookup = lookup @keycolumn = keycolumn @target = targetfield @conditions = conditions @result_type = result_type @selector = Lookup::RowSelector.call( conditions: conditions ) end |
Instance Method Details
#process(row) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/kiba/extend/transforms/count/matching_rows_in_lookup.rb', line 32 def process(row) id = row.fetch(keycolumn) matches = lookup.fetch(id, []) if matches.size.zero? row[target] = finalize(0) else merge_rows = selector.call( origrow: row, mergerows: matches ) row[target] = finalize(merge_rows.size) end row end |