Class: Kiba::Extend::Transforms::Warn::IfFieldValueMatches
- Inherits:
 - 
      Object
      
        
- Object
 - Kiba::Extend::Transforms::Warn::IfFieldValueMatches
 
 
- Includes:
 - SingleWarnable
 
- Defined in:
 - lib/kiba/extend/transforms/warn/if_field_value_matches.rb
 
Overview
Prints single warning to STDOUT if the value of the given field matches the given value in any rows
Useful if you have skipped mapping/setting up transforms for certain values in an initial/staging data set, but need to ensure you will notice if later/production data includes new values that need attention.
Publicly available example of use in kiba-tms
Uses Utils::FieldValueMatcher to determine whether value matches. See that class’ documentation for examples
This transform warns if Utils::FieldValueMatcher finds a match.
Instance Method Summary collapse
- 
  
    
      #initialize(field:, match:, matchmode: :plain, delim: nil, treat_as_null: nil, casesensitive: true, strip: true, multimode: :any)  ⇒ IfFieldValueMatches 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of IfFieldValueMatches.
 - 
  
    
      #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: :any) ⇒ IfFieldValueMatches
Returns a new instance of IfFieldValueMatches.
      36 37 38 39 40 41 42 43 44 45 46  | 
    
      # File 'lib/kiba/extend/transforms/warn/if_field_value_matches.rb', line 36 def initialize(field:, match:, matchmode: :plain, delim: nil, treat_as_null: nil, casesensitive: true, strip: true, multimode: :any) @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
      49 50 51 52 53 54 55 56 57 58  | 
    
      # File 'lib/kiba/extend/transforms/warn/if_field_value_matches.rb', line 49 def process(row) return row unless single_warnings.empty? result = matcher.call(row) return row unless result msg = "One or more rows has #{field} value matching #{match}" add_single_warning(msg) row end  |