Class: Kiba::Extend::Transforms::Clean::RegexpFindReplaceFieldVals
- Inherits:
-
Object
- Object
- Kiba::Extend::Transforms::Clean::RegexpFindReplaceFieldVals
- Includes:
- Allable
- Defined in:
- lib/kiba/extend/transforms/clean/regexp_find_replace_field_vals.rb
Overview
Performs specified regular expression find/replace in the specified field(s)
Instance Method Summary collapse
-
#initialize(fields:, find:, replace:, casesensitive: true, multival: false, sep: nil, debug: false) ⇒ RegexpFindReplaceFieldVals
constructor
A new instance of RegexpFindReplaceFieldVals.
-
#process(row) ⇒ Object
Constructor Details
#initialize(fields:, find:, replace:, casesensitive: true, multival: false, sep: nil, debug: false) ⇒ RegexpFindReplaceFieldVals
Returns a new instance of RegexpFindReplaceFieldVals.
232 233 234 235 236 237 238 239 240 |
# File 'lib/kiba/extend/transforms/clean/regexp_find_replace_field_vals.rb', line 232 def initialize(fields:, find:, replace:, casesensitive: true, multival: false, sep: nil, debug: false) @fields = [fields].flatten @find = build_pattern(find, casesensitive) @replace = replace @debug = debug @mv = multival @sep = set_sep(sep) end |
Instance Method Details
#process(row) ⇒ Object
243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/kiba/extend/transforms/clean/regexp_find_replace_field_vals.rb', line 243 def process(row) finalize_fields(row) fields.each do |field| oldval = row.fetch(field, nil) next if oldval.nil? next unless oldval.is_a?(String) newval = mv ? mv_find_replace(oldval) : sv_find_replace(oldval) target = debug ? "#{field}_repl".to_sym : field row[target] = newval.blank? ? nil : newval end row end |