Class: Probe::ColumnMeetsCondition
- Inherits:
-
RowMeetsCondition
- Object
- RowMeetsCondition
- Probe::ColumnMeetsCondition
- Defined in:
- lib/csv/probe/checks.rb
Overview
Abstract class of a CSV::Row single field (= column) check
Direct Known Subclasses
ColumnIsDate, ColumnIsEqualTo, ColumnIsListWithDomain, ColumnIsOneOf, ColumnIsSet, ColumnIsSetWithDomain, ColumnMatchesRegEx, ColumnNotMatchesRegEx
Instance Attribute Summary collapse
-
#fail_msg ⇒ Object
Returns the value of attribute fail_msg.
-
#ok_condition_fn ⇒ Object
Returns the value of attribute ok_condition_fn.
-
#varname ⇒ Object
Returns the value of attribute varname.
Attributes inherited from RowMeetsCondition
Instance Method Summary collapse
- #evaluate(row, opts = {}) ⇒ Object
-
#initialize(varname, ok_condition_fn, fail_msg) ⇒ ColumnMeetsCondition
constructor
A new instance of ColumnMeetsCondition.
- #render_pretty_fail_msg(row, opts) ⇒ Object
Methods inherited from RowMeetsCondition
#error_msg, #evaluate_pre_checks, #render_fail_msg, #report_columns_hash, #source_row, #source_row_location
Constructor Details
#initialize(varname, ok_condition_fn, fail_msg) ⇒ ColumnMeetsCondition
Returns a new instance of ColumnMeetsCondition.
116 117 118 119 120 121 122 123 |
# File 'lib/csv/probe/checks.rb', line 116 def initialize(varname, ok_condition_fn, fail_msg) super(ok_condition_fn, fail_msg) @varname = varname @error_classes = { "ERROR" => ColumnError, "WARNING" => ColumnWarning } end |
Instance Attribute Details
#fail_msg ⇒ Object
Returns the value of attribute fail_msg.
114 115 116 |
# File 'lib/csv/probe/checks.rb', line 114 def fail_msg @fail_msg end |
#ok_condition_fn ⇒ Object
Returns the value of attribute ok_condition_fn.
114 115 116 |
# File 'lib/csv/probe/checks.rb', line 114 def ok_condition_fn @ok_condition_fn end |
#varname ⇒ Object
Returns the value of attribute varname.
114 115 116 |
# File 'lib/csv/probe/checks.rb', line 114 def varname @varname end |
Instance Method Details
#evaluate(row, opts = {}) ⇒ Object
129 130 131 132 133 134 135 |
# File 'lib/csv/probe/checks.rb', line 129 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) ⇒ Object
125 126 127 |
# File 'lib/csv/probe/checks.rb', line 125 def render_pretty_fail_msg(row, opts) "Unexpected value:#{row.fetch(@varname).inspect} for column:#{@varname.inspect}, #{render_fail_msg(row, opts)}" end |