class Probe::ColumnMeetsCondition

Abstract class of a CSV::Row single field (= column) check

Attributes

fail_msg[RW]
ok_condition_fn[RW]
varname[RW]

Public Class Methods

new(varname, ok_condition_fn, fail_msg) click to toggle source
Calls superclass method Probe::RowMeetsCondition::new
# File lib/csv/probe/checks.rb, line 114
def initialize(varname, ok_condition_fn, fail_msg)
  super(ok_condition_fn, fail_msg)
  @varname = varname
  @error_classes = {
    "ERROR" => ColumnError,
    "WARNING" => ColumnWarning
  }
end

Public Instance Methods

evaluate(row, opts = {}) click to toggle source
# File lib/csv/probe/checks.rb, line 127
def evaluate(row, opts = {})
  evaluate_pre_checks(row, opts)

  unless @ok_condition_fn.call(row.fetch(@varname), opts) # rubocop:disable Style/GuardClause
    raise @error_classes.fetch(@severity), error_msg(row, opts)
  end
end
render_pretty_fail_msg(row, opts) click to toggle source
# File lib/csv/probe/checks.rb, line 123
def render_pretty_fail_msg(row, opts)
  "Unexpected value:#{row.fetch(@varname).inspect} for column:#{@varname.inspect}, #{render_fail_msg(row, opts)}"
end