license-validator 0.0.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/license-validator.rb +112 -0
- data/lib/license_validator/driver.rb +69 -0
- data/lib/license_validator/states.rb +14 -0
- data/lib/license_validator/validations/base.rb +63 -0
- data/lib/license_validator/validations/state_ak.rb +24 -0
- data/lib/license_validator/validations/state_al.rb +28 -0
- data/lib/license_validator/validations/state_ar.rb +20 -0
- data/lib/license_validator/validations/state_az.rb +32 -0
- data/lib/license_validator/validations/state_ca.rb +20 -0
- data/lib/license_validator/validations/state_co.rb +24 -0
- data/lib/license_validator/validations/state_ct.rb +41 -0
- data/lib/license_validator/validations/state_dc.rb +24 -0
- data/lib/license_validator/validations/state_de.rb +16 -0
- data/lib/license_validator/validations/state_fl.rb +16 -0
- data/lib/license_validator/validations/state_ga.rb +28 -0
- data/lib/license_validator/validations/state_hi.rb +28 -0
- data/lib/license_validator/validations/state_ia.rb +23 -0
- data/lib/license_validator/validations/state_id.rb +28 -0
- data/lib/license_validator/validations/state_il.rb +16 -0
- data/lib/license_validator/validations/state_in.rb +16 -0
- data/lib/license_validator/validations/state_ks.rb +26 -0
- data/lib/license_validator/validations/state_ky.rb +20 -0
- data/lib/license_validator/validations/state_la.rb +16 -0
- data/lib/license_validator/validations/state_ma.rb +23 -0
- data/lib/license_validator/validations/state_md.rb +23 -0
- data/lib/license_validator/validations/state_me.rb +16 -0
- data/lib/license_validator/validations/state_mi.rb +16 -0
- data/lib/license_validator/validations/state_mn.rb +16 -0
- data/lib/license_validator/validations/state_mo.rb +32 -0
- data/lib/license_validator/validations/state_ms.rb +16 -0
- data/lib/license_validator/validations/state_mt.rb +42 -0
- data/lib/license_validator/validations/state_nc.rb +24 -0
- data/lib/license_validator/validations/state_nd.rb +20 -0
- data/lib/license_validator/validations/state_ne.rb +16 -0
- data/lib/license_validator/validations/state_nh.rb +31 -0
- data/lib/license_validator/validations/state_nj.rb +16 -0
- data/lib/license_validator/validations/state_nm.rb +16 -0
- data/lib/license_validator/validations/state_nv.rb +21 -0
- data/lib/license_validator/validations/state_ny.rb +32 -0
- data/lib/license_validator/validations/state_oh.rb +20 -0
- data/lib/license_validator/validations/state_ok.rb +20 -0
- data/lib/license_validator/validations/state_or.rb +26 -0
- data/lib/license_validator/validations/state_pa.rb +20 -0
- data/lib/license_validator/validations/state_ri.rb +20 -0
- data/lib/license_validator/validations/state_sc.rb +16 -0
- data/lib/license_validator/validations/state_sd.rb +20 -0
- data/lib/license_validator/validations/state_tn.rb +20 -0
- data/lib/license_validator/validations/state_tx.rb +24 -0
- data/lib/license_validator/validations/state_ut.rb +16 -0
- data/lib/license_validator/validations/state_va.rb +16 -0
- data/lib/license_validator/validations/state_vt.rb +16 -0
- data/lib/license_validator/validations/state_wa.rb +23 -0
- data/lib/license_validator/validations/state_wi.rb +16 -0
- data/lib/license_validator/validations/state_wv.rb +27 -0
- data/lib/license_validator/validations/state_wy.rb +16 -0
- data/lib/license_validator/validators.rb +5 -0
- data/lib/license_validator/version.rb +1 -1
- metadata +85 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 765d257c1c164253fc920091c417c0b23315ddee7e4d1be7cf2b53d0afa31e53
|
4
|
+
data.tar.gz: 9cdb4da632bdacc45fdeec2b0532e9b747f0b92f60646cf3f2779af52f6520a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8397c4a34805f88648398cf4a2e9787255b803413f88e13c37d4d2aa81d99df5b4b9c5544bb5b6f938d7d5afc51515d891d232f5a4d300af8b858856f91449f1
|
7
|
+
data.tar.gz: 273c364371d31a1810e29446786c46326b1385438a58cad2448ec61ecf170564f71e2b34da9e7467b0bd01ea98d837cda73d330408df39292cdf6072b0916f72
|
data/lib/license-validator.rb
CHANGED
@@ -1,6 +1,118 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'active_model'
|
4
|
+
|
5
|
+
require_relative 'license_validator/states'
|
6
|
+
|
7
|
+
require_relative 'license_validator/driver'
|
8
|
+
require_relative 'license_validator/validators'
|
3
9
|
require_relative 'license_validator/version'
|
4
10
|
|
5
11
|
module LicenseValidator
|
12
|
+
# Validates the provided driver's DL#
|
13
|
+
#
|
14
|
+
# @raise [ActiveModel::ValidationError] if driver is invalid
|
15
|
+
#
|
16
|
+
# @see LicenseValidator::Driver#new params
|
17
|
+
#
|
18
|
+
# @return [Hash]
|
19
|
+
#
|
20
|
+
def validate!(**kwargs)
|
21
|
+
driver = LicenseValidator::Driver.new(**kwargs)
|
22
|
+
|
23
|
+
validator =
|
24
|
+
LicenseValidator::Validations
|
25
|
+
.const_get("LicenseValidator::Validations::State#{driver.state.capitalize}")
|
26
|
+
.new(driver)
|
27
|
+
|
28
|
+
validator.validate
|
29
|
+
|
30
|
+
return validator.validation_results
|
31
|
+
end
|
32
|
+
|
33
|
+
module_function :validate!
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
# Only for development
|
38
|
+
def generate_state_files
|
39
|
+
LicenseValidator::States::ABVS.each do |abv|
|
40
|
+
ruby = <<~RUBY
|
41
|
+
# frozen_string_literal: true
|
42
|
+
|
43
|
+
module LicenseValidator
|
44
|
+
module Validations
|
45
|
+
class State#{abv.capitalize} < LicenseValidator::Validations::Base
|
46
|
+
def initialize(driver)
|
47
|
+
super(driver)
|
48
|
+
end
|
49
|
+
|
50
|
+
# @see super
|
51
|
+
def validate
|
52
|
+
super
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
RUBY
|
58
|
+
|
59
|
+
File.write("lib/license_validator/validations/state_#{abv.downcase}.rb", ruby)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
module_function :generate_state_files
|
64
|
+
|
65
|
+
# Only for development
|
66
|
+
def generate_test_files
|
67
|
+
LicenseValidator::States::ABVS.each do |abv|
|
68
|
+
test = <<~SPEC
|
69
|
+
# frozen_string_literal: true
|
70
|
+
|
71
|
+
state_klass = LicenseValidator::Validations::State#{abv.capitalize}
|
72
|
+
|
73
|
+
module ValidAttributes
|
74
|
+
module State#{abv.capitalize}
|
75
|
+
# @see super
|
76
|
+
def valid_attributes
|
77
|
+
super.map do |valid_attrs|
|
78
|
+
valid_attrs
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# @see super
|
83
|
+
def invalid_attributes
|
84
|
+
super.map do |invalid_attrs|
|
85
|
+
invalid_attrs
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
# @see super
|
92
|
+
def valid_license_nums
|
93
|
+
%w[AB123456]
|
94
|
+
end
|
95
|
+
|
96
|
+
# @see super
|
97
|
+
def invalid_license_nums
|
98
|
+
%w[AB]
|
99
|
+
end
|
100
|
+
|
101
|
+
# @see super
|
102
|
+
def state
|
103
|
+
'#{abv}'
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
state_klass.extend(ValidAttributes::State#{abv.capitalize})
|
109
|
+
|
110
|
+
test_klass(state_klass)
|
111
|
+
SPEC
|
112
|
+
|
113
|
+
File.write("spec/license_validator/validations/state_#{abv.downcase}_spec.rb", test)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
module_function :generate_test_files
|
6
118
|
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LicenseValidator
|
4
|
+
class Driver
|
5
|
+
include ActiveModel::Model
|
6
|
+
|
7
|
+
validates :age, numericality: { greater_than_or_equal_to: 0 }, if: -> (d) { d.dob.present? }
|
8
|
+
validates :cdl_class, inclusion: { in: ['A', 'B', 'No CDL'], message: 'is invalid' }
|
9
|
+
validates :license_num, presence: true
|
10
|
+
validates :state, inclusion: { in: LicenseValidator::States::ABVS, message: 'is invalid' }
|
11
|
+
validates :years_exp, numericality: { greater_than_or_equal_to: 0 }
|
12
|
+
|
13
|
+
# @return [Integer]
|
14
|
+
attr_accessor :age
|
15
|
+
# @return [Boolean]
|
16
|
+
attr_accessor :bad
|
17
|
+
# @return [String]
|
18
|
+
attr_accessor :cdl_class
|
19
|
+
# @return [Date]
|
20
|
+
attr_accessor :dob
|
21
|
+
# @return [String]
|
22
|
+
attr_accessor :first_name
|
23
|
+
# @return [String]
|
24
|
+
attr_accessor :last_name
|
25
|
+
# @return [String]
|
26
|
+
attr_accessor :license_num
|
27
|
+
# @return [String] abv
|
28
|
+
attr_accessor :state
|
29
|
+
# @return [Integer]
|
30
|
+
attr_accessor :years_exp
|
31
|
+
|
32
|
+
# @see super
|
33
|
+
def self.human_attribute_name(attr, options = {})
|
34
|
+
return 'CDL Class' if attr == 'cdl_class'
|
35
|
+
|
36
|
+
return 'License #' if attr == 'license_num'
|
37
|
+
|
38
|
+
super
|
39
|
+
end
|
40
|
+
|
41
|
+
# @param attributes [Hash]
|
42
|
+
def initialize(attributes = {})
|
43
|
+
super
|
44
|
+
|
45
|
+
if dob.blank? && !dob.is_a?(Date)
|
46
|
+
@dob = nil
|
47
|
+
end
|
48
|
+
|
49
|
+
@license_num = license_num.to_s
|
50
|
+
|
51
|
+
validate!
|
52
|
+
end
|
53
|
+
|
54
|
+
# @return [Hash]
|
55
|
+
def attributes
|
56
|
+
{
|
57
|
+
state: state,
|
58
|
+
years_exp: years_exp,
|
59
|
+
dob: dob,
|
60
|
+
age: age,
|
61
|
+
cdl_class: cdl_class,
|
62
|
+
license_num: license_num,
|
63
|
+
first_name: first_name,
|
64
|
+
last_name: last_name,
|
65
|
+
bad: bad
|
66
|
+
}
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LicenseValidator
|
4
|
+
module States
|
5
|
+
ABVS = %w[
|
6
|
+
AK AL AR AZ CA CO CT DE FL GA
|
7
|
+
HI IA ID IL IN KS KY LA MA MD
|
8
|
+
ME MI MN MO MS MT NC ND NE NH
|
9
|
+
NJ NM NV NY OH OK OR PA RI SC
|
10
|
+
SD TN TX UT VA VT WA WI WV WY
|
11
|
+
DC
|
12
|
+
].freeze
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LicenseValidator
|
4
|
+
module Validations
|
5
|
+
class Base
|
6
|
+
# @return [LicenseValidator::Driver]
|
7
|
+
attr_accessor :driver
|
8
|
+
# @return [ActiveModel::Errors]
|
9
|
+
attr_accessor :errors
|
10
|
+
# @return [ActiveModel::Errors]
|
11
|
+
attr_accessor :infos
|
12
|
+
# @return [ActiveModel::Errors]
|
13
|
+
attr_accessor :warnings
|
14
|
+
|
15
|
+
# @param driver [LicenseValidator::Driver]
|
16
|
+
def initialize(driver)
|
17
|
+
@errors = ActiveModel::Errors.new(self)
|
18
|
+
@warnings = ActiveModel::Errors.new(self)
|
19
|
+
@infos = ActiveModel::Errors.new(self)
|
20
|
+
|
21
|
+
@driver = driver
|
22
|
+
end
|
23
|
+
|
24
|
+
# Common validations
|
25
|
+
def validate
|
26
|
+
return if driver.dob.nil?
|
27
|
+
|
28
|
+
age = driver.age
|
29
|
+
|
30
|
+
if age < 21
|
31
|
+
warnings.add(:dob, 'Drivers under 21 do not qualify for an interstate CDL.')
|
32
|
+
elsif age < 23
|
33
|
+
warnings.add(
|
34
|
+
:dob,
|
35
|
+
'Drivers under 23 are underage for all markets unless underwriters have specifically approved.'
|
36
|
+
)
|
37
|
+
elsif age > 65
|
38
|
+
warnings.add(
|
39
|
+
:dob,
|
40
|
+
[
|
41
|
+
'Drivers is older than 65, check underwriting guidelines to determine if they should be submitted',
|
42
|
+
'for approval.'
|
43
|
+
].join(' ')
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
return unless driver.bad
|
48
|
+
|
49
|
+
warnings.add(:bad, 'Driver is on the bad drivers list.')
|
50
|
+
end
|
51
|
+
|
52
|
+
# @return [Hash]
|
53
|
+
def validation_results
|
54
|
+
{
|
55
|
+
errors: errors,
|
56
|
+
warnings: warnings,
|
57
|
+
infos: infos,
|
58
|
+
validated_with: driver.attributes
|
59
|
+
}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LicenseValidator
|
4
|
+
module Validations
|
5
|
+
class StateAk < LicenseValidator::Validations::Base
|
6
|
+
# @see super
|
7
|
+
def validate
|
8
|
+
super
|
9
|
+
|
10
|
+
unless driver.license_num.match?(/\A\d{7}\z/i)
|
11
|
+
errors.add(:license_num, 'License number requires 7 numeric digits for AK.')
|
12
|
+
end
|
13
|
+
|
14
|
+
if driver.last_name.blank?
|
15
|
+
errors.add(:last_name, 'Last name required for AK.')
|
16
|
+
end
|
17
|
+
|
18
|
+
return if driver.dob.present?
|
19
|
+
|
20
|
+
errors.add(:dob, 'D.O.B. required for AK.')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LicenseValidator
|
4
|
+
module Validations
|
5
|
+
class StateAl < LicenseValidator::Validations::Base
|
6
|
+
# @see super
|
7
|
+
def validate
|
8
|
+
super
|
9
|
+
|
10
|
+
lic_num = driver.license_num
|
11
|
+
|
12
|
+
return if lic_num.match?(/\A\d{7,8}\z/i)
|
13
|
+
|
14
|
+
return if lic_num.match?(/\A[a-z]\d{6,8}\z/i)
|
15
|
+
|
16
|
+
return if lic_num.match?(/\AID\d{5,6}\z/i)
|
17
|
+
|
18
|
+
errors.add(
|
19
|
+
:license_num,
|
20
|
+
[
|
21
|
+
'License number requires 7-8 Numeric or "I", 6-8 Numeric or "ID", 5-6 Numeric or 1 Alphabetic, 6-8 Numeric',
|
22
|
+
'for AL'
|
23
|
+
].join(' ')
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LicenseValidator
|
4
|
+
module Validations
|
5
|
+
class StateAr < LicenseValidator::Validations::Base
|
6
|
+
# @see super
|
7
|
+
def validate
|
8
|
+
super
|
9
|
+
|
10
|
+
unless driver.license_num.match?(/\A\d{9}\z/i)
|
11
|
+
errors.add(:license_num, 'License number requires 9 numeric digits for AR.')
|
12
|
+
end
|
13
|
+
|
14
|
+
return if driver.dob.present?
|
15
|
+
|
16
|
+
errors.add(:dob, 'D.O.B. is required for AR.')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LicenseValidator
|
4
|
+
module Validations
|
5
|
+
class StateAz < LicenseValidator::Validations::Base
|
6
|
+
# @see super
|
7
|
+
def validate
|
8
|
+
super
|
9
|
+
|
10
|
+
if driver.last_name.blank?
|
11
|
+
errors.add(:last_name, 'Last name required for AZ.')
|
12
|
+
end
|
13
|
+
|
14
|
+
if driver.first_name.blank?
|
15
|
+
errors.add(:first_name, 'First name required for AZ.')
|
16
|
+
end
|
17
|
+
|
18
|
+
if driver.dob.blank?
|
19
|
+
errors.add(:dob, 'D.O.B. required for AZ.')
|
20
|
+
end
|
21
|
+
|
22
|
+
lic_num = driver.license_num
|
23
|
+
|
24
|
+
return if lic_num.match?(/\A[a-z]\d{8}\z/i)
|
25
|
+
|
26
|
+
return if lic_num.match?(/\A\d{9}\z/i)
|
27
|
+
|
28
|
+
errors.add(:license_num, 'License number requires 1 Alphabetic, 8 Numeric or 9 Numeric for AZ.')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LicenseValidator
|
4
|
+
module Validations
|
5
|
+
class StateCa < LicenseValidator::Validations::Base
|
6
|
+
# @see super
|
7
|
+
def validate
|
8
|
+
super
|
9
|
+
|
10
|
+
unless driver.license_num.match?(/\A[a-z]\d{7}\z/i)
|
11
|
+
errors.add(:license_num, 'License number requires 1 Alphabetic, 7 Numeric for CA.')
|
12
|
+
end
|
13
|
+
|
14
|
+
return if driver.last_name.present?
|
15
|
+
|
16
|
+
errors.add(:last_name, 'Last name required for CA.')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LicenseValidator
|
4
|
+
module Validations
|
5
|
+
class StateCo < LicenseValidator::Validations::Base
|
6
|
+
# @see super
|
7
|
+
def validate
|
8
|
+
super
|
9
|
+
|
10
|
+
if driver.dob.blank?
|
11
|
+
errors.add(:dob, 'D.O.B. is required for CO.')
|
12
|
+
end
|
13
|
+
|
14
|
+
lic_num = driver.license_num
|
15
|
+
|
16
|
+
return if lic_num.match?(/\A\d{9}\z/i)
|
17
|
+
|
18
|
+
return if lic_num.match?(/\A[a-z]\d{3,6}\z/i)
|
19
|
+
|
20
|
+
errors.add(:license_num, 'License number requires 9 numeric or 1 alphabetic, 3-6 numeric for CO.')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LicenseValidator
|
4
|
+
module Validations
|
5
|
+
class StateCt < LicenseValidator::Validations::Base
|
6
|
+
# @see super
|
7
|
+
def validate
|
8
|
+
super
|
9
|
+
|
10
|
+
if driver.last_name.blank?
|
11
|
+
errors.add(:last_name, 'Last name required for CT.')
|
12
|
+
end
|
13
|
+
|
14
|
+
# 9 Numeric, 1st two positions are month of birth in odd or
|
15
|
+
# even year. 01-12 Jan-Dec odd years, 13 - 24 Jan-Dec even years, 99 unknown
|
16
|
+
|
17
|
+
if driver.dob.blank?
|
18
|
+
errors.add(:dob, 'D.O.B. is required for CT.')
|
19
|
+
|
20
|
+
return
|
21
|
+
end
|
22
|
+
|
23
|
+
year = driver.dob.year
|
24
|
+
month = driver.dob.month
|
25
|
+
|
26
|
+
month += 12 if year.even?
|
27
|
+
|
28
|
+
month = "#{0 if month < 10}#{month}"
|
29
|
+
|
30
|
+
regex = Regexp.new("\\A#{month}\\d{7}\\z", 'i')
|
31
|
+
|
32
|
+
return if driver.license_num.match?(regex)
|
33
|
+
|
34
|
+
errors.add(
|
35
|
+
:license_num,
|
36
|
+
"License number requires 9 numeric for CT. For DOB in #{year}, license number must start with #{month}"
|
37
|
+
)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LicenseValidator
|
4
|
+
module Validations
|
5
|
+
class StateDc < LicenseValidator::Validations::Base
|
6
|
+
# @see super
|
7
|
+
def validate
|
8
|
+
super
|
9
|
+
|
10
|
+
unless driver.license_num.match?(/\A[a-z0-9]{7,9}\z/i)
|
11
|
+
errors.add(:license_num, 'License number requires 7-9 alphanumeric for DC.')
|
12
|
+
end
|
13
|
+
|
14
|
+
if driver.last_name.blank?
|
15
|
+
errors.add(:last_name, 'Last name required for DC.')
|
16
|
+
end
|
17
|
+
|
18
|
+
return if driver.dob.present?
|
19
|
+
|
20
|
+
errors.add(:dob, 'D.O.B. required for DC.')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LicenseValidator
|
4
|
+
module Validations
|
5
|
+
class StateDe < LicenseValidator::Validations::Base
|
6
|
+
# @see super
|
7
|
+
def validate
|
8
|
+
super
|
9
|
+
|
10
|
+
return if driver.license_num.match?(/\A\d{1,7}\z/i)
|
11
|
+
|
12
|
+
errors.add(:license_num, 'License requires 1-7 numeric for DE.')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LicenseValidator
|
4
|
+
module Validations
|
5
|
+
class StateFl < LicenseValidator::Validations::Base
|
6
|
+
# @see super
|
7
|
+
def validate
|
8
|
+
super
|
9
|
+
|
10
|
+
return if driver.license_num.match?(/\A[a-zA-Z]\d{12}\z/i)
|
11
|
+
|
12
|
+
errors.add(:license_num, 'License number requires 1 alphabetic and 12 numeric for FL.')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LicenseValidator
|
4
|
+
module Validations
|
5
|
+
class StateGa < LicenseValidator::Validations::Base
|
6
|
+
# @see super
|
7
|
+
def validate
|
8
|
+
super
|
9
|
+
|
10
|
+
unless driver.license_num.match?(/\A\d{9}\z/i)
|
11
|
+
errors.add(:license_num, 'License number requires 9 numeric digits for GA.')
|
12
|
+
end
|
13
|
+
|
14
|
+
if driver.first_name.blank?
|
15
|
+
errors.add(:first_name, 'First name required for GA.')
|
16
|
+
end
|
17
|
+
|
18
|
+
if driver.last_name.blank?
|
19
|
+
errors.add(:last_name, 'Last name required for GA.')
|
20
|
+
end
|
21
|
+
|
22
|
+
return if driver.dob.present?
|
23
|
+
|
24
|
+
errors.add(:dob, 'D.O.B. required for GA.')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LicenseValidator
|
4
|
+
module Validations
|
5
|
+
class StateHi < LicenseValidator::Validations::Base
|
6
|
+
# @see super
|
7
|
+
def validate
|
8
|
+
super
|
9
|
+
|
10
|
+
if driver.last_name.blank?
|
11
|
+
errors.add(:last_name, 'Last name required for HI.')
|
12
|
+
end
|
13
|
+
|
14
|
+
if driver.dob.blank?
|
15
|
+
errors.add(:dob, 'D.O.B. required for HI.')
|
16
|
+
end
|
17
|
+
|
18
|
+
lic_num = driver.license_num
|
19
|
+
|
20
|
+
return if lic_num.match?(/\A\d{9}\z/i)
|
21
|
+
|
22
|
+
return if lic_num.match?(/\AH\d{8}\z/i)
|
23
|
+
|
24
|
+
errors.add(:license_num, 'License number needs 9 numeric or "H", 8 numeric for HI.')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LicenseValidator
|
4
|
+
module Validations
|
5
|
+
class StateIa < LicenseValidator::Validations::Base
|
6
|
+
# @see super
|
7
|
+
def validate
|
8
|
+
super
|
9
|
+
|
10
|
+
lic_num = driver.license_num
|
11
|
+
|
12
|
+
return if lic_num.match?(/\A\d{3}[a-z]{2}\d{4}\z/i)
|
13
|
+
|
14
|
+
return if lic_num.match?(/\A\d{9}\z/i)
|
15
|
+
|
16
|
+
errors.add(
|
17
|
+
:license_num,
|
18
|
+
'License number requires 3 Numeric and 2 Alphabetic and 4 Numeric, or 9 numeric for IA.'
|
19
|
+
)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LicenseValidator
|
4
|
+
module Validations
|
5
|
+
class StateId < LicenseValidator::Validations::Base
|
6
|
+
# @see super
|
7
|
+
def validate
|
8
|
+
super
|
9
|
+
|
10
|
+
if driver.last_name.blank?
|
11
|
+
errors.add(:last_name, 'Last name required for ID.')
|
12
|
+
end
|
13
|
+
|
14
|
+
if driver.dob.blank?
|
15
|
+
errors.add(:dob, 'D.O.B. required for ID.')
|
16
|
+
end
|
17
|
+
|
18
|
+
lic_num = driver.license_num
|
19
|
+
|
20
|
+
return if lic_num.match?(/\A[a-z]{2}\d{6}[a-z]\z/i)
|
21
|
+
|
22
|
+
return if lic_num.match?(/\A\d{9}\z/i)
|
23
|
+
|
24
|
+
errors.add(:license_num, 'License number requires 2 Alphabetic, 6 Numeric, 1 Alphabetic or 9 Numeric for ID.')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LicenseValidator
|
4
|
+
module Validations
|
5
|
+
class StateIl < LicenseValidator::Validations::Base
|
6
|
+
# @see super
|
7
|
+
def validate
|
8
|
+
super
|
9
|
+
|
10
|
+
return if driver.license_num.match?(/\A[a-z]\d{11}\z/i)
|
11
|
+
|
12
|
+
errors.add(:license_num, 'License number requires 1 alphabetic and 11 numeric for IL.')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LicenseValidator
|
4
|
+
module Validations
|
5
|
+
class StateIn < LicenseValidator::Validations::Base
|
6
|
+
# @see super
|
7
|
+
def validate
|
8
|
+
super
|
9
|
+
|
10
|
+
return if driver.license_num.match?(/\A\d{10}\z/i)
|
11
|
+
|
12
|
+
errors.add(:license_num, 'License number requires 10 numeric digits for IN.')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|