license-validator 1.4.1 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.adoc +7 -0
- data/lib/license-validator.rb +33 -36
- data/lib/license_validator/validations/base.rb +1 -0
- data/lib/license_validator/validations/state_mb.rb +3 -0
- data/lib/license_validator/validations/state_mt.rb +2 -12
- data/lib/license_validator/validations/state_nb.rb +2 -2
- data/lib/license_validator/validations/state_ns.rb +2 -8
- data/lib/license_validator/validations/state_pe.rb +2 -8
- data/lib/license_validator/validators.rb +2 -0
- data/lib/license_validator/version.rb +15 -1
- metadata +14 -29
- data/lib/tasks/generator.rake +0 -74
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21b1222b3a183a38fc79efd31ceb0c0cc8e8156c221f39effb529e40f8f4abb4
|
4
|
+
data.tar.gz: 33581bd7e5b6b0cdf02294585099df33df501e47057fb604195054879b9e3426
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59375de8407d1bbff7b27bc20ccda9c3c5de29946dd8c5d79c24e3bdf5fdcb76a472636ace187e2c549e52c91ab903aa24d1296ac3f3acdd5eda0172fe41c42b
|
7
|
+
data.tar.gz: 65b9afd4e0ea906ccbc05aa2ba418df21bd70774cc07abfe487f8c1599ba5b09971287d27d0a588a166bb6330be8933746d28d4bd19ed58fc226fa3c0a45622c
|
data/CHANGELOG.adoc
CHANGED
data/lib/license-validator.rb
CHANGED
@@ -9,6 +9,8 @@ require_relative 'license_validator/validators'
|
|
9
9
|
require_relative 'license_validator/version'
|
10
10
|
|
11
11
|
module LicenseValidator
|
12
|
+
module_function
|
13
|
+
|
12
14
|
# Validates the provided driver's DL#
|
13
15
|
#
|
14
16
|
# @raise [ActiveModel::ValidationError] if driver is invalid
|
@@ -30,8 +32,6 @@ module LicenseValidator
|
|
30
32
|
return validator.validation_results
|
31
33
|
end
|
32
34
|
|
33
|
-
module_function :validate!
|
34
|
-
|
35
35
|
private
|
36
36
|
|
37
37
|
# Only for development
|
@@ -60,59 +60,56 @@ module LicenseValidator
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
module_function :generate_state_files
|
64
|
-
|
65
63
|
# Only for development
|
66
64
|
def generate_test_files
|
67
65
|
LicenseValidator::States::ABVS.each do |abv|
|
68
66
|
test = <<~SPEC
|
69
67
|
# frozen_string_literal: true
|
70
68
|
|
71
|
-
|
69
|
+
RSpec.describe(LicenseValidator::Validations::State#{abv.capitalize}) do
|
70
|
+
valid_license_nums = %w[123456789 934292912 191919191 894894384 921098585]
|
71
|
+
invalid_license_nums = %w[A11333333 19191919119 1BNS12343 0929292B 02902922A]
|
72
|
+
|
73
|
+
let(:driver) do
|
74
|
+
LicenseValidator::Driver.new({
|
75
|
+
cdl_class: 'A',
|
76
|
+
years_exp: 5,
|
77
|
+
state: state,
|
78
|
+
license_num: license_num,
|
79
|
+
dob: Date.parse('1990-01-01', '%F'),
|
80
|
+
age: 33
|
81
|
+
})
|
82
|
+
end
|
72
83
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
end
|
84
|
+
valid_license_nums.each do |valid_num|
|
85
|
+
context "when #\{valid_num}" do
|
86
|
+
let(:license_num) { valid_num }
|
87
|
+
|
88
|
+
it 'does not have an error' do
|
89
|
+
validator = described_class.new(driver)
|
90
|
+
validator.validate
|
81
91
|
|
82
|
-
|
83
|
-
def invalid_attributes
|
84
|
-
super.map do |invalid_attrs|
|
85
|
-
invalid_attrs
|
92
|
+
expect(validator.validation_results.fetch(:errors).blank?).to(be(true))
|
86
93
|
end
|
87
94
|
end
|
95
|
+
end
|
88
96
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
def valid_license_nums
|
93
|
-
%w[AB123456]
|
94
|
-
end
|
97
|
+
invalid_license_nums.each do |invalid_num|
|
98
|
+
context "when #\{invalid_num}" do
|
99
|
+
let(:license_num) { invalid_num }
|
95
100
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
end
|
101
|
+
it 'does have an error' do
|
102
|
+
validator = described_class.new(driver)
|
103
|
+
validator.validate
|
100
104
|
|
101
|
-
|
102
|
-
def state
|
103
|
-
'#{abv}'
|
105
|
+
expect(validator.validation_results.fetch(:errors).present?).to(be(true))
|
104
106
|
end
|
107
|
+
end
|
105
108
|
end
|
106
109
|
end
|
107
|
-
|
108
|
-
state_klass.extend(ValidAttributes::State#{abv.capitalize})
|
109
|
-
|
110
|
-
test_klass(state_klass)
|
111
110
|
SPEC
|
112
111
|
|
113
112
|
File.write("spec/license_validator/validations/state_#{abv.downcase}_spec.rb", test)
|
114
113
|
end
|
115
114
|
end
|
116
|
-
|
117
|
-
module_function :generate_test_files
|
118
115
|
end
|
@@ -28,8 +28,11 @@ module LicenseValidator
|
|
28
28
|
expected_date_of_birth = (100 - driver.dob.strftime('%y').to_i).to_s.rjust(2, '0')[-2..]
|
29
29
|
|
30
30
|
last_name = driver.last_name[0, 5].ljust(5, '*')
|
31
|
+
last_name.gsub!('*', '\\*')
|
31
32
|
|
33
|
+
# rubocop:disable Style/ArrayFirstLast
|
32
34
|
first_initial = driver.first_name[0]
|
35
|
+
# rubocop:enable Style/ArrayFirstLast
|
33
36
|
|
34
37
|
regex = Regexp.new("\\A#{last_name}#{first_initial}[a-z*]#{expected_date_of_birth}[A-Z0-9]{3}\\z", 'i')
|
35
38
|
|
@@ -21,21 +21,11 @@ module LicenseValidator
|
|
21
21
|
|
22
22
|
lic_num = driver.license_num
|
23
23
|
|
24
|
-
return if lic_num.match?(/\A
|
25
|
-
|
26
|
-
return if lic_num.match?(/\A\d{13}\z/i)
|
27
|
-
|
28
|
-
return if lic_num.match?(/\A[a-z]{3}\d{10}\z/i)
|
24
|
+
return if lic_num.match?(/\A\d{13}[a-z]{3}\d{10}\z/i)
|
29
25
|
|
30
26
|
return if lic_num.match?(/\A\d{9}\z/i)
|
31
27
|
|
32
|
-
errors.add(
|
33
|
-
:license_num,
|
34
|
-
[
|
35
|
-
'License number requires 1 alpha, 1 numeric, 1 alphanumeric, 2 numeric, 3 alpha, 1 numeric or 13 numeric',
|
36
|
-
'or 3 alpha, 10 numeric or 9 numeric for MT.'
|
37
|
-
].join(' ')
|
38
|
-
)
|
28
|
+
errors.add(:license_num, 'License number requires 13 numeric, 3 alpha, 10 numeric or 9 numeric for MT.')
|
39
29
|
end
|
40
30
|
end
|
41
31
|
end
|
@@ -7,12 +7,12 @@ module LicenseValidator
|
|
7
7
|
def validate
|
8
8
|
super
|
9
9
|
|
10
|
-
return if driver.license_num.match?(/\A\d{7}\z/i)
|
10
|
+
return if driver.license_num.match?(/\A\d{1,7}\z/i)
|
11
11
|
|
12
12
|
errors.add(
|
13
13
|
:license_num,
|
14
14
|
[
|
15
|
-
'License number requires 7 numeric',
|
15
|
+
'License number requires 1-7 numeric',
|
16
16
|
'for NB'
|
17
17
|
].join(' ')
|
18
18
|
)
|
@@ -7,15 +7,9 @@ module LicenseValidator
|
|
7
7
|
def validate
|
8
8
|
super
|
9
9
|
|
10
|
-
return if driver.license_num.match?(/\A[
|
10
|
+
return if driver.license_num.match?(/\A[a-z]{5}\d{9}\z/i)
|
11
11
|
|
12
|
-
errors.add(
|
13
|
-
:license_num,
|
14
|
-
[
|
15
|
-
'License number requires 1 alphabetic, 4 alphabetic or asterisk, and 9 numeric',
|
16
|
-
'for NS'
|
17
|
-
].join(' ')
|
18
|
-
)
|
12
|
+
errors.add(:license_num, 'License number requires 5 alphabetic, 9 numeric for NS')
|
19
13
|
end
|
20
14
|
end
|
21
15
|
end
|
@@ -7,15 +7,9 @@ module LicenseValidator
|
|
7
7
|
def validate
|
8
8
|
super
|
9
9
|
|
10
|
-
return if driver.license_num.match?(/\A\d{
|
10
|
+
return if driver.license_num.match?(/\A\d{1,6}\z/i)
|
11
11
|
|
12
|
-
errors.add(
|
13
|
-
:license_num,
|
14
|
-
[
|
15
|
-
'License number requires 5 numeric',
|
16
|
-
'for PE'
|
17
|
-
].join(' ')
|
18
|
-
)
|
12
|
+
errors.add(:license_num, 'License number requires 1-6 numeric for PE')
|
19
13
|
end
|
20
14
|
end
|
21
15
|
end
|
@@ -1,5 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module LicenseValidator
|
4
|
-
VERSION
|
4
|
+
module VERSION
|
5
|
+
MAJOR = 1
|
6
|
+
MINOR = 5
|
7
|
+
TINY = 0
|
8
|
+
|
9
|
+
# Set PRE to nil unless it's a pre-release (beta, rc, etc.)
|
10
|
+
PRE = nil
|
11
|
+
|
12
|
+
STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.').freeze
|
13
|
+
|
14
|
+
# @return [String]
|
15
|
+
def self.to_s
|
16
|
+
STRING
|
17
|
+
end
|
18
|
+
end
|
5
19
|
end
|
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: license-validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.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: 2025-
|
11
|
+
date: 2025-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activemodel
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
20
|
-
|
19
|
+
version: 6.0.3.6
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '7.1'
|
23
|
+
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 6.0.3.6
|
30
|
+
- - "<"
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1
|
32
|
+
version: '7.1'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: concurrent-ruby
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,26 +50,6 @@ dependencies:
|
|
44
50
|
- - "<"
|
45
51
|
- !ruby/object:Gem::Version
|
46
52
|
version: 1.3.4
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: activemodel
|
49
|
-
requirement: !ruby/object:Gem::Requirement
|
50
|
-
requirements:
|
51
|
-
- - ">="
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: 6.0.3.6
|
54
|
-
- - "<"
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version: '7.1'
|
57
|
-
type: :runtime
|
58
|
-
prerelease: false
|
59
|
-
version_requirements: !ruby/object:Gem::Requirement
|
60
|
-
requirements:
|
61
|
-
- - ">="
|
62
|
-
- !ruby/object:Gem::Version
|
63
|
-
version: 6.0.3.6
|
64
|
-
- - "<"
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
version: '7.1'
|
67
53
|
description:
|
68
54
|
email:
|
69
55
|
- documents@brandsinsurance.com
|
@@ -144,7 +130,6 @@ files:
|
|
144
130
|
- lib/license_validator/validations/state_yt.rb
|
145
131
|
- lib/license_validator/validators.rb
|
146
132
|
- lib/license_validator/version.rb
|
147
|
-
- lib/tasks/generator.rake
|
148
133
|
homepage: https://github.com/brandsinsurance/license-validator/
|
149
134
|
licenses:
|
150
135
|
- MIT
|
data/lib/tasks/generator.rake
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
namespace :generate do
|
2
|
-
desc "Generate blank state and spec files. Usage: rake generate:state[al]"
|
3
|
-
task :state, [:state] do |t, args|
|
4
|
-
require 'erb'
|
5
|
-
|
6
|
-
state = args[:state]
|
7
|
-
raise "Please supply a state argument" unless state
|
8
|
-
|
9
|
-
state_title = state.capitalize
|
10
|
-
state_upcase = state.upcase
|
11
|
-
|
12
|
-
state_rb = <<~RUBY
|
13
|
-
# frozen_string_literal: true
|
14
|
-
|
15
|
-
module LicenseValidator
|
16
|
-
module Validations
|
17
|
-
class State#{state_title} < LicenseValidator::Validations::Base
|
18
|
-
# @see super
|
19
|
-
def validate
|
20
|
-
super
|
21
|
-
|
22
|
-
errors.add(
|
23
|
-
:license_num,
|
24
|
-
[
|
25
|
-
'',
|
26
|
-
'for #{state_upcase}'
|
27
|
-
].join(' ')
|
28
|
-
)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
RUBY
|
34
|
-
|
35
|
-
spec_rb = <<~RUBY
|
36
|
-
# frozen_string_literal: true
|
37
|
-
|
38
|
-
state_klass = LicenseValidator::Validations::State#{state_title}
|
39
|
-
|
40
|
-
module ValidAttributes
|
41
|
-
module State#{state_title}
|
42
|
-
private
|
43
|
-
|
44
|
-
# @see super
|
45
|
-
def valid_license_nums
|
46
|
-
%w[
|
47
|
-
|
48
|
-
]
|
49
|
-
end
|
50
|
-
|
51
|
-
# @see super
|
52
|
-
def invalid_license_nums
|
53
|
-
%w[
|
54
|
-
|
55
|
-
]
|
56
|
-
end
|
57
|
-
|
58
|
-
# @see super
|
59
|
-
def state
|
60
|
-
'#{state_upcase}'
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
state_klass.extend(ValidAttributes::State#{state_title})
|
66
|
-
|
67
|
-
test_klass(state_klass)
|
68
|
-
RUBY
|
69
|
-
|
70
|
-
File.write("lib/license_validator/validations/state_#{state.downcase}.rb", state_rb)
|
71
|
-
File.write("spec/license_validator/validations/state_#{state.downcase}_spec.rb", spec_rb)
|
72
|
-
puts "Generated files for #{state_upcase}"
|
73
|
-
end
|
74
|
-
end
|