Class: LIVR::Rules::Special::IsoDate

Inherits:
LIVR::Rule show all
Defined in:
lib/livr/rules/special.rb

Instance Method Summary collapse

Methods inherited from LIVR::Rule

#initialize

Constructor Details

This class inherits a constructor from LIVR::Rule

Instance Method Details

#call(value, user_data, field_results) ⇒ Object


50
51
52
53
54
55
56
57
58
59
60
# File 'lib/livr/rules/special.rb', line 50

def call(value, user_data, field_results)
  return if is_no_value(value)
  return 'FORMAT_ERROR' if !is_primitive(value)

  return "WRONG_DATE" unless value.length == "YYYY-MM-DD".length

  date = Date.strptime(value, '%Y-%m-%d') rescue nil
  unless date
    return "WRONG_DATE"
  end
end