license-validator 1.0.0.pre.rc.1 → 1.0.1.pre.rc.1
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 +2 -4
- data/lib/license_validator/driver.rb +14 -12
- data/lib/license_validator/validations/base.rb +24 -4
- data/lib/license_validator/validations/state_al.rb +2 -0
- data/lib/license_validator/validations/state_az.rb +1 -0
- data/lib/license_validator/validations/state_co.rb +1 -0
- data/lib/license_validator/validations/state_ct.rb +2 -0
- data/lib/license_validator/validations/state_hi.rb +1 -0
- data/lib/license_validator/validations/state_ia.rb +1 -0
- data/lib/license_validator/validations/state_id.rb +1 -0
- data/lib/license_validator/validations/state_ks.rb +2 -0
- data/lib/license_validator/validations/state_ky.rb +1 -0
- data/lib/license_validator/validations/state_ma.rb +1 -0
- data/lib/license_validator/validations/state_md.rb +1 -0
- data/lib/license_validator/validations/state_mo.rb +4 -0
- data/lib/license_validator/validations/state_mt.rb +3 -0
- data/lib/license_validator/validations/state_nd.rb +1 -0
- data/lib/license_validator/validations/state_nh.rb +1 -0
- data/lib/license_validator/validations/state_ny.rb +4 -0
- data/lib/license_validator/validations/state_oh.rb +1 -0
- data/lib/license_validator/validations/state_or.rb +2 -0
- data/lib/license_validator/validations/state_ri.rb +1 -0
- data/lib/license_validator/validations/state_sd.rb +1 -0
- data/lib/license_validator/validations/state_wv.rb +1 -0
- data/lib/license_validator/validators.rb +1 -1
- data/lib/license_validator/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: caf6ea101c3510f78fa8fbf1706440efc19f35b127cfe17548e75ffb318a82aa
|
4
|
+
data.tar.gz: d421d36045261f2a2a2511b52b70154d5ff0827fe22c40445f6c432fe07d184a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c246727a3c6bc3334618b0c2e1de468de81af0bd9dcab6b8adf6c572f31036325e5b6b6fba43436ae7600850b0ce749824671bc9f328f1791196e0260e09ca3
|
7
|
+
data.tar.gz: 1833b407af5ac22b46c9e3b6291b3dd655a212667b37e762b7c4e61e39eec96ab6e352e2c5242d219ecd5a0cf554bce0bf36bc11bb71bcd490c9303d7fd642cb
|
data/lib/license-validator.rb
CHANGED
@@ -11,17 +11,15 @@ require_relative 'license_validator/version'
|
|
11
11
|
module LicenseValidator
|
12
12
|
# Validates the provided driver's DL#
|
13
13
|
#
|
14
|
-
# @param @see LicenseValidator::Driver attributes
|
15
|
-
#
|
16
14
|
# @raise [ActiveModel::ValidationError] if driver is invalid
|
17
15
|
#
|
16
|
+
# @see LicenseValidator::Driver#new params
|
17
|
+
#
|
18
18
|
# @return [Hash]
|
19
19
|
#
|
20
20
|
def validate!(**kwargs)
|
21
21
|
driver = LicenseValidator::Driver.new(**kwargs)
|
22
22
|
|
23
|
-
puts(driver)
|
24
|
-
|
25
23
|
validator =
|
26
24
|
LicenseValidator::Validations
|
27
25
|
.const_get("LicenseValidator::Validations::State#{driver.state.capitalize}")
|
@@ -4,39 +4,41 @@ module LicenseValidator
|
|
4
4
|
class Driver
|
5
5
|
include ActiveModel::Model
|
6
6
|
|
7
|
-
validates :
|
7
|
+
validates :age, numericality: { greater_than_or_equal_to: 0 }, if: -> (d) { d.dob.present? }
|
8
8
|
validates :cdl_class, inclusion: { in: ['A', 'B', 'No CDL'], message: 'is invalid' }
|
9
|
+
validates :license_num, presence: true
|
9
10
|
validates :state, inclusion: { in: LicenseValidator::States::ABVS, message: 'is invalid' }
|
10
11
|
validates :years_exp, numericality: { greater_than_or_equal_to: 0 }
|
11
|
-
validates :age, numericality: { greater_than_or_equal_to: 0 }, if: -> (d) { d.dob.present? }
|
12
12
|
|
13
|
-
# @return [String] abv
|
14
|
-
attr_accessor :state
|
15
|
-
# @return [Integer]
|
16
|
-
attr_accessor :years_exp
|
17
|
-
# @return [Date]
|
18
|
-
attr_accessor :dob
|
19
13
|
# @return [Integer]
|
20
14
|
attr_accessor :age
|
15
|
+
# @return [Boolean]
|
16
|
+
attr_accessor :bad
|
21
17
|
# @return [String]
|
22
18
|
attr_accessor :cdl_class
|
23
|
-
# @return [
|
24
|
-
attr_accessor :
|
19
|
+
# @return [Date]
|
20
|
+
attr_accessor :dob
|
25
21
|
# @return [String]
|
26
22
|
attr_accessor :first_name
|
27
23
|
# @return [String]
|
28
24
|
attr_accessor :last_name
|
29
|
-
# @return [
|
30
|
-
attr_accessor :
|
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
31
|
|
32
32
|
# @see super
|
33
33
|
def self.human_attribute_name(attr, options = {})
|
34
34
|
return 'CDL Class' if attr == 'cdl_class'
|
35
|
+
|
35
36
|
return 'License #' if attr == 'license_num'
|
36
37
|
|
37
38
|
super
|
38
39
|
end
|
39
40
|
|
41
|
+
# @param attributes [Hash]
|
40
42
|
def initialize(attributes = {})
|
41
43
|
super
|
42
44
|
|
@@ -3,15 +3,30 @@
|
|
3
3
|
module LicenseValidator
|
4
4
|
module Validations
|
5
5
|
class Base
|
6
|
+
extend ActiveModel::Naming
|
7
|
+
|
8
|
+
# @return [LicenseValidator::Driver]
|
9
|
+
attr_accessor :driver
|
6
10
|
# @return [ActiveModel::Errors]
|
7
11
|
attr_accessor :errors
|
8
12
|
# @return [ActiveModel::Errors]
|
9
|
-
attr_accessor :warnings
|
10
|
-
# @return [ActiveModel::Errors]
|
11
13
|
attr_accessor :infos
|
12
|
-
# @return [
|
13
|
-
attr_accessor :
|
14
|
+
# @return [ActiveModel::Errors]
|
15
|
+
attr_accessor :warnings
|
16
|
+
|
17
|
+
class << self
|
18
|
+
# Necessary for ActiveModel::Errors https://api.rubyonrails.org/classes/ActiveModel/Errors.html
|
19
|
+
def lookup_ancestors
|
20
|
+
[self]
|
21
|
+
end
|
22
|
+
|
23
|
+
# Necessary for ActiveModel::Errors https://api.rubyonrails.org/classes/ActiveModel/Errors.html
|
24
|
+
def human_attribute_name(attr, _options = {})
|
25
|
+
attr
|
26
|
+
end
|
27
|
+
end
|
14
28
|
|
29
|
+
# @param driver [LicenseValidator::Driver]
|
15
30
|
def initialize(driver)
|
16
31
|
@errors = ActiveModel::Errors.new(self)
|
17
32
|
@warnings = ActiveModel::Errors.new(self)
|
@@ -20,6 +35,11 @@ module LicenseValidator
|
|
20
35
|
@driver = driver
|
21
36
|
end
|
22
37
|
|
38
|
+
# Necessary for ActiveModel::Errors https://api.rubyonrails.org/classes/ActiveModel/Errors.html
|
39
|
+
def read_attribute_for_validation(attr)
|
40
|
+
__send__(attr)
|
41
|
+
end
|
42
|
+
|
23
43
|
# Common validations
|
24
44
|
def validate
|
25
45
|
return if driver.dob.nil?
|
@@ -18,6 +18,7 @@ module LicenseValidator
|
|
18
18
|
lic_num = driver.license_num
|
19
19
|
|
20
20
|
return if lic_num.match?(/\A[a-z]{2}\d{6}[a-z]\z/i)
|
21
|
+
|
21
22
|
return if lic_num.match?(/\A\d{9}\z/i)
|
22
23
|
|
23
24
|
errors.add(:license_num, 'License number requires 2 Alphabetic, 6 Numeric, 1 Alphabetic or 9 Numeric for ID.')
|
@@ -14,7 +14,9 @@ module LicenseValidator
|
|
14
14
|
lic_num = driver.license_num
|
15
15
|
|
16
16
|
return if lic_num.match?(/\AK\d{8}\z/i)
|
17
|
+
|
17
18
|
return if lic_num.match?(/\A[0-9a-z]{6}\z/i)
|
19
|
+
|
18
20
|
return if lic_num.match?(/\A\d{9}\z/i)
|
19
21
|
|
20
22
|
errors.add(:license_num, 'License number requires “K” and 8 Numeric, 6 Alphanumeric, or 9 numeric for KS.')
|
@@ -10,9 +10,13 @@ module LicenseValidator
|
|
10
10
|
lic_num = driver.license_num
|
11
11
|
|
12
12
|
return if lic_num.match?(/\A\d{3}[a-z]\d{6}\z/i)
|
13
|
+
|
13
14
|
return if lic_num.match?(/\A[a-z]\d{5,9}\z/i)
|
15
|
+
|
14
16
|
return if lic_num.match?(/\A\d{9}[a-z]?\z/i)
|
17
|
+
|
15
18
|
return if lic_num.match?(/\A[a-z]\d{8}MA\z/i)
|
19
|
+
|
16
20
|
return if lic_num.match?(/\A\d{15}\z/i)
|
17
21
|
|
18
22
|
errors.add(
|
@@ -22,8 +22,11 @@ module LicenseValidator
|
|
22
22
|
lic_num = driver.license_num
|
23
23
|
|
24
24
|
return if lic_num.match?(/\A[a-z]\d[0-9a-z]\d{2}[a-z]{3}\d\z/i)
|
25
|
+
|
25
26
|
return if lic_num.match?(/\A\d{13}\z/i)
|
27
|
+
|
26
28
|
return if lic_num.match?(/\A[a-z]{3}\d{10}\z/i)
|
29
|
+
|
27
30
|
return if lic_num.match?(/\A\d{9}\z/i)
|
28
31
|
|
29
32
|
errors.add(
|
@@ -10,9 +10,13 @@ module LicenseValidator
|
|
10
10
|
lic_num = driver.license_num
|
11
11
|
|
12
12
|
return if lic_num.match?(/\A\d{8,9}\z/i)
|
13
|
+
|
13
14
|
return if lic_num.match?(/\A[a-z]\d{7}\z/i)
|
15
|
+
|
14
16
|
return if lic_num.match?(/\A[a-z]{8}\z/i)
|
17
|
+
|
15
18
|
return if lic_num.match?(/\A\d{16}\z/i)
|
19
|
+
|
16
20
|
return if lic_num.match?(/\A[a-z]\d{18}\z/i)
|
17
21
|
|
18
22
|
errors.add(
|
@@ -14,7 +14,9 @@ module LicenseValidator
|
|
14
14
|
license = driver.license_num
|
15
15
|
|
16
16
|
return if license.match?(/\A\d{9}\z/i)
|
17
|
+
|
17
18
|
return if license.match?(/\A[a-z]\d{6}\z/i)
|
19
|
+
|
18
20
|
return if license.match?(/\A\d{7}\z/i)
|
19
21
|
|
20
22
|
errors.add(:license_num, 'License number requires 9 Numeric or 1 Alpha, 6 numeric, or 7 numeric for OR.')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: license-validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1.pre.rc.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brands Insurance
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-08-
|
11
|
+
date: 2023-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop-rubomatic
|