class Probe::ColumnIsListWithDomain
rubocop:disable Metrics/AbcSize Check if a tokenized column value is a list of given values
Public Class Methods
new(varname, expected_items_arr, separator, _placeholder = nil)
click to toggle source
Calls superclass method
Probe::ColumnMeetsCondition::new
# File lib/csv/probe/checks.rb, line 192 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