Class: LicenseValidator::Validations::StateMt

Inherits:
Base
  • Object
show all
Defined in:
lib/license_validator/validations/state_mt.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
39
# File 'lib/license_validator/validations/state_mt.rb', line 7

def validate
  super

  if driver.first_name.blank?
    errors.add(:first_name, 'First name required for MT.')
  end

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

  if driver.dob.blank?
    errors.add(:dbo, 'D.O.B. required for MT.')
  end

  lic_num = driver.license_num

  return if lic_num.match?(/\A[a-z]\d[0-9a-z]\d{2}[a-z]{3}\d\z/i)

  return if lic_num.match?(/\A\d{13}\z/i)

  return if lic_num.match?(/\A[a-z]{3}\d{10}\z/i)

  return if lic_num.match?(/\A\d{9}\z/i)

  errors.add(
    :license_num,
    [
      'License number requires 1 alpha, 1 numeric, 1 alphanumeric, 2 numeric, 3 alpha, 1 numeric or 13 numeric',
      'or 3 alpha, 10 numeric or 9 numeric for MT.'
    ].join(' ')
  )
end