Class: LicenseValidator::Validations::StateCt

Inherits:
Base
  • Object
show all
Defined in:
lib/license_validator/validations/state_ct.rb

Instance Attribute Summary

Attributes inherited from Base

#driver, #errors, #infos, #warnings

Instance Method Summary collapse

Methods inherited from Base

human_attribute_name, #initialize, lookup_ancestors, #read_attribute_for_validation, #validation_results

Constructor Details

This class inherits a constructor from LicenseValidator::Validations::Base

Instance Method Details

#validateObject

See Also:

  • super


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/license_validator/validations/state_ct.rb', line 7

def validate
  super

  if driver.last_name.blank?
    errors.add(:last_name, 'Last name required for CT.')
  end

  # 9 numeric, 1st two positions are month of birth in odd or
  # even year. 01-12 Jan-Dec odd years, 13 - 24 Jan-Dec even years, 99 unknown

  if driver.dob.blank?
    errors.add(:dob, 'D.O.B. is required for CT.')

    return
  end

  year = driver.dob.year
  month = driver.dob.month

  month += 12 if year.even?

  month = "#{0 if month < 10}#{month}"

  regex = Regexp.new("\\A#{month}\\d{7}\\z", 'i')

  return if driver.license_num.match?(regex)

  errors.add(
    :license_num,
    "License number requires 9 numeric for CT. For DOB in #{year}, license number must start with #{month}"
  )
end