Class: Kiba::Extend::Transforms::Warn::UnlessFieldValueMatches
- Inherits:
-
Object
- Object
- Kiba::Extend::Transforms::Warn::UnlessFieldValueMatches
- Includes:
- SingleWarnable
- Defined in:
- lib/kiba/extend/transforms/warn/unless_field_value_matches.rb
Overview
Prints single warning to STDOUT if the value of the given field does not match match the given value in any rows
Useful for getting notification that assumptions made during initial transformation development have changed in subsequent data.
Uses Utils::FieldValueMatcher to determine whether value matches. See that class’ documentation for examples/more details on parameters.
This transform warns if Utils::FieldValueMatcher does not find a match
Instance Method Summary collapse
-
#initialize(field:, match:, matchmode: :plain, delim: nil, treat_as_null: nil, casesensitive: true, strip: true, multimode: :all) ⇒ UnlessFieldValueMatches
constructor
A new instance of UnlessFieldValueMatches.
-
#process(row) ⇒ Object
Methods included from SingleWarnable
Constructor Details
#initialize(field:, match:, matchmode: :plain, delim: nil, treat_as_null: nil, casesensitive: true, strip: true, multimode: :all) ⇒ UnlessFieldValueMatches
Returns a new instance of UnlessFieldValueMatches.
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/kiba/extend/transforms/warn/unless_field_value_matches.rb', line 33 def initialize(field:, match:, matchmode: :plain, delim: nil, treat_as_null: nil, casesensitive: true, strip: true, multimode: :all) @field = field @match = match @matcher = Utils::FieldValueMatcher.new( field: field, match: match, matchmode: matchmode, delim: delim, treat_as_null: treat_as_null, casesensitive: casesensitive, strip: strip, multimode: multimode ) setup_single_warning end |
Instance Method Details
#process(row) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/kiba/extend/transforms/warn/unless_field_value_matches.rb', line 46 def process(row) return row unless single_warnings.empty? return row if row[field].blank? result = matcher.call(row) return row if result msg = "One or more rows has #{field} value not matching #{match}" add_single_warning(msg) row end |