license-validator 1.0.0.pre.rc.1 → 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 +2 -4
- data/lib/license_validator/driver.rb +14 -12
- data/lib/license_validator/validations/base.rb +5 -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 +4 -4
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
@@ -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,16 @@
|
|
3
3
|
module LicenseValidator
|
4
4
|
module Validations
|
5
5
|
class Base
|
6
|
+
# @return [LicenseValidator::Driver]
|
7
|
+
attr_accessor :driver
|
6
8
|
# @return [ActiveModel::Errors]
|
7
9
|
attr_accessor :errors
|
8
10
|
# @return [ActiveModel::Errors]
|
9
|
-
attr_accessor :warnings
|
10
|
-
# @return [ActiveModel::Errors]
|
11
11
|
attr_accessor :infos
|
12
|
-
# @return [
|
13
|
-
attr_accessor :
|
12
|
+
# @return [ActiveModel::Errors]
|
13
|
+
attr_accessor :warnings
|
14
14
|
|
15
|
+
# @param driver [LicenseValidator::Driver]
|
15
16
|
def initialize(driver)
|
16
17
|
@errors = ActiveModel::Errors.new(self)
|
17
18
|
@warnings = ActiveModel::Errors.new(self)
|
@@ -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.0
|
4
|
+
version: 1.0.0
|
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
|
@@ -138,9 +138,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
138
138
|
version: 2.5.3
|
139
139
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
140
|
requirements:
|
141
|
-
- - "
|
141
|
+
- - ">="
|
142
142
|
- !ruby/object:Gem::Version
|
143
|
-
version:
|
143
|
+
version: '0'
|
144
144
|
requirements: []
|
145
145
|
rubygems_version: 3.4.10
|
146
146
|
signing_key:
|