Class: Probe::ColumnIsDate

Inherits:
ColumnMeetsCondition show all
Defined in:
lib/csv/probe/checks.rb

Overview

Check if a column value is a date with a given format

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

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_date_format, _placeholder = nil) ⇒ ColumnIsDate

rubocop:disable Metrics/MethodLength



158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/csv/probe/checks.rb', line 158

def initialize(varname, expected_date_format, _placeholder = nil) # rubocop:disable Metrics/MethodLength
  super(varname, nil, nil)
  @ok_condition_fn = lambda { |val, _cfg|
    success = true
    begin
      Date.strptime(val, expected_date_format)
    rescue Date::Error
      success = false
    end
    return success
  }
  @fail_msg = "expected date with format #{expected_date_format.inspect}"
end