Class: Probe::ColumnIsListWithDomain
- Inherits:
-
ColumnMeetsCondition
- Object
- RowMeetsCondition
- ColumnMeetsCondition
- Probe::ColumnIsListWithDomain
- Defined in:
- lib/csv/probe/checks.rb
Overview
rubocop:disable Metrics/AbcSize Check if a tokenized column value is a list of given values
Instance Attribute Summary
Attributes inherited from ColumnMeetsCondition
#fail_msg, #ok_condition_fn, #varname
Attributes inherited from RowMeetsCondition
#fail_msg, #ok_condition_fn, #pre_checks, #severity
Instance Method Summary collapse
-
#initialize(varname, expected_items_arr, separator, _placeholder = nil) ⇒ ColumnIsListWithDomain
constructor
rubocop:disable Metrics/MethodLength.
Methods inherited from ColumnMeetsCondition
#evaluate, #render_pretty_fail_msg
Methods inherited from RowMeetsCondition
#error_msg, #evaluate, #evaluate_pre_checks, #render_fail_msg, #render_pretty_fail_msg, #report_columns_hash, #source_row, #source_row_location
Constructor Details
#initialize(varname, expected_items_arr, separator, _placeholder = nil) ⇒ ColumnIsListWithDomain
rubocop:disable Metrics/MethodLength
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/csv/probe/checks.rb', line 203 def initialize(varname, expected_items_arr, separator, _placeholder = nil) # rubocop:disable Metrics/MethodLength super(varname, nil, nil) @ok_condition_fn = lambda { |val, _cfg| expected_items_arr.map!(&:to_s) # turn nil -> "" items = val.to_s.split(separator, -1) return true if items.empty? && expected_items_arr.include?(nil.to_s) # empty str allowed return false if items.empty? return items.all? { |e| expected_items_arr.include?(e) } } @fail_msg = lambda { |row, _opts| items = row.fetch(@varname).to_s.split(separator, -1) diff_items = items - expected_items_arr "expected that tokenized items of value #{items.inspect} are a subset of "\ "#{expected_items_arr.inspect}, but items #{diff_items.inspect} are not" } end |