Class: Kiba::Extend::Transforms::Count::UniqueVals
- Inherits:
-
Object
- Object
- Kiba::Extend::Transforms::Count::UniqueVals
- Defined in:
- lib/kiba/extend/transforms/count/unique_vals.rb
Overview
Note:
This transform runs in memory, so for very large sources, it may take a long time or fail.
Write count of unique values in field to the given target field. Optionally, group the values under another field for counting
Instance Method Summary collapse
-
#close ⇒ Object
-
#initialize(value_field:, target:, group_field: nil, casesensitive: true, count_blank: false) ⇒ UniqueVals
constructor
A new instance of UniqueVals.
-
#process(row) ⇒ Object
Constructor Details
#initialize(value_field:, target:, group_field: nil, casesensitive: true, count_blank: false) ⇒ UniqueVals
Returns a new instance of UniqueVals.
154 155 156 157 158 159 160 161 162 163 |
# File 'lib/kiba/extend/transforms/count/unique_vals.rb', line 154 def initialize(value_field:, target:, group_field: nil, casesensitive: true, count_blank: false) @value_field = value_field @target = target @group_field = group_field @casesensitive = casesensitive @count_blank = count_blank @grouper = {} @rows = [] end |
Instance Method Details
#close ⇒ Object
172 173 174 175 |
# File 'lib/kiba/extend/transforms/count/unique_vals.rb', line 172 def close @ct = grouper.keys.length unless group_field rows.each { |row| yield add_count_to(row) } end |
#process(row) ⇒ Object
166 167 168 169 170 |
# File 'lib/kiba/extend/transforms/count/unique_vals.rb', line 166 def process(row) extract_for_count(row) rows << row nil end |