license-validator 1.3.0 → 1.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4466c0920ddf18e76fb944a0ff75e8ac4b35ed370a8ad1957ebf96b5490262db
4
- data.tar.gz: 552e2b1986e685dbbdf2d3c77ea7e65a755c40d70f8ced1eeafa536130ae3250
3
+ metadata.gz: 5e089c9fc57e3cdc81cb5d08126067bdb73be93489830b7f6c08a6594b5247c6
4
+ data.tar.gz: 06e189d43fa9ba0efa7688efcf088bdfa329977ff6d03ee8199fda7eb6e1a6cd
5
5
  SHA512:
6
- metadata.gz: 57d90f6b0856726851bf1a7db479536f4ec9b0dbb5515fcd73d12cb3039b58422f0050925a6d4c13ed4fe2a2f1c796468003e4a3f05a17429a4dd9c40244bf72
7
- data.tar.gz: 41e8cacce9f7f17c656887014a4ce5fe79d55ee5baec69246b41deb2c5d803792e0f918471aa96af05f221cb2858e740294b8ed2c40522078de4d4e39eacc243
6
+ metadata.gz: 4ea6541c5aee572f2974ea47f7fa556ccbefa93a9e539179c294dca2f208d199640d2a6f58791567959060250342510a26cb9e0c20716143d8c9fee2d802f1af
7
+ data.tar.gz: ab2de537fc9497fa6cae73d1c8a6361e8e9ae59d6279c7ee378d880416d324c4471c6e42bb3b1887ecd1c01753785fd0847a2300bd821bbfdf55f1c08d8974a8
data/CHANGELOG.adoc CHANGED
@@ -1,3 +1,7 @@
1
+ == 1.4.0
2
+
3
+ * Add support for validating Canadian licenses
4
+
1
5
  == 1.3.0
2
6
 
3
7
  * Allowed more up to date version of ``activemodel`` (< ``7.1``)
@@ -2,7 +2,7 @@
2
2
 
3
3
  module LicenseValidator
4
4
  module States
5
- ABVS = %w[
5
+ US = %w[
6
6
  AK AL AR AZ CA CO CT DE FL GA
7
7
  HI IA ID IL IN KS KY LA MA MD
8
8
  ME MI MN MO MS MT NC ND NE NH
@@ -10,5 +10,9 @@ module LicenseValidator
10
10
  SD TN TX UT VA VT WA WI WV WY
11
11
  DC
12
12
  ].freeze
13
+
14
+ CANADA = %w[AB BC MB NB NL NS NT NU ON PE QC SK YT].freeze
15
+
16
+ ABVS = (US + CANADA).freeze
13
17
  end
14
18
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LicenseValidator
4
+ module Validations
5
+ class StateAb < LicenseValidator::Validations::Base
6
+ # @see super
7
+ def validate
8
+ super
9
+
10
+ return if driver.license_num.match?(/\A\d{9}\z/i)
11
+
12
+ errors.add(
13
+ :license_num,
14
+ [
15
+ 'License number requires 9 numeric',
16
+ 'for AB'
17
+ ].join(' ')
18
+ )
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LicenseValidator
4
+ module Validations
5
+ class StateBc < LicenseValidator::Validations::Base
6
+ # @see super
7
+ def validate
8
+ super
9
+
10
+ return if driver.license_num.match?(/\A\d{7}\z/i)
11
+
12
+ errors.add(
13
+ :license_num,
14
+ [
15
+ 'License number requires 7 numeric',
16
+ 'for BC'
17
+ ].join(' ')
18
+ )
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LicenseValidator
4
+ module Validations
5
+ class StateMb < LicenseValidator::Validations::Base
6
+ # @see super
7
+ def validate
8
+ super
9
+
10
+ return if driver.license_num.match?(/\A[a-z][a-z*]{4}[a-z][a-z*][a-z0-9]{2}[0-9][a-z0-9]{2}[0-9]\z/i)
11
+
12
+ errors.add(
13
+ :license_num,
14
+ [
15
+ 'License number requires 1 alphabetic, 4 alphanumeric or asterisk, 1 alphabetic, 1 alphabetic or asterisk,',
16
+ '2 alphanumeric, 1 numeric, 2 alphanumeric, and 1 numeric',
17
+ 'for MB'
18
+ ].join(' ')
19
+ )
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LicenseValidator
4
+ module Validations
5
+ class StateNb < LicenseValidator::Validations::Base
6
+ # @see super
7
+ def validate
8
+ super
9
+
10
+ return if driver.license_num.match?(/\A\d{7}\z/i)
11
+
12
+ errors.add(
13
+ :license_num,
14
+ [
15
+ 'License number requires 7 numeric',
16
+ 'for NB'
17
+ ].join(' ')
18
+ )
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LicenseValidator
4
+ module Validations
5
+ class StateNl < LicenseValidator::Validations::Base
6
+ # @see super
7
+ def validate
8
+ super
9
+
10
+ return if driver.license_num.match?(/\A[A-Z]\d{9}\z/i)
11
+
12
+ errors.add(
13
+ :license_num,
14
+ [
15
+ 'License number requires 1 alphabetic, 9 numeric',
16
+ 'for NL'
17
+ ].join(' ')
18
+ )
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LicenseValidator
4
+ module Validations
5
+ class StateNs < LicenseValidator::Validations::Base
6
+ # @see super
7
+ def validate
8
+ super
9
+
10
+ return if driver.license_num.match?(/\A[A-Z][A-Z*]{4}\d{9}\z/i)
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
+ )
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LicenseValidator
4
+ module Validations
5
+ class StateNt < LicenseValidator::Validations::Base
6
+ # @see super
7
+ def validate
8
+ super
9
+
10
+ return if driver.license_num.match?(/\A\d{9}\z/i)
11
+
12
+ errors.add(
13
+ :license_num,
14
+ [
15
+ 'License number requires 9 numeric',
16
+ 'for NT'
17
+ ].join(' ')
18
+ )
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LicenseValidator
4
+ module Validations
5
+ class StateNu < LicenseValidator::Validations::Base
6
+ # @see super
7
+ def validate
8
+ super
9
+
10
+ return if driver.license_num.match?(/\A\d{5}\z/i)
11
+
12
+ errors.add(
13
+ :license_num,
14
+ [
15
+ 'License number requires 5 numeric',
16
+ 'for NU'
17
+ ].join(' ')
18
+ )
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LicenseValidator
4
+ module Validations
5
+ class StateOn < LicenseValidator::Validations::Base
6
+ # @see super
7
+ def validate
8
+ super
9
+
10
+ return if driver.license_num.match?(/\A[A-Z]\d{14}\z/i)
11
+
12
+ errors.add(
13
+ :license_num,
14
+ [
15
+ 'License number requires 1 alphabetic, 14 numeric',
16
+ 'for ON'
17
+ ].join(' ')
18
+ )
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LicenseValidator
4
+ module Validations
5
+ class StatePe < LicenseValidator::Validations::Base
6
+ # @see super
7
+ def validate
8
+ super
9
+
10
+ return if driver.license_num.match?(/\A\d{5}\z/i)
11
+
12
+ errors.add(
13
+ :license_num,
14
+ [
15
+ 'License number requires 5 numeric',
16
+ 'for PE'
17
+ ].join(' ')
18
+ )
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LicenseValidator
4
+ module Validations
5
+ class StateQc < LicenseValidator::Validations::Base
6
+ # @see super
7
+ def validate
8
+ super
9
+
10
+ return if driver.license_num.match?(/\A[A-Z]\d{12}\z/i)
11
+
12
+ errors.add(
13
+ :license_num,
14
+ [
15
+ 'License number requires 1 alphabetic, 12 numeric',
16
+ 'for QC'
17
+ ].join(' ')
18
+ )
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LicenseValidator
4
+ module Validations
5
+ class StateSk < LicenseValidator::Validations::Base
6
+ # @see super
7
+ def validate
8
+ super
9
+
10
+ return if driver.license_num.match?(/\A\d{8}\z/i)
11
+
12
+ errors.add(
13
+ :license_num,
14
+ [
15
+ 'License number requires 8 numeric',
16
+ 'for SK'
17
+ ].join(' ')
18
+ )
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LicenseValidator
4
+ module Validations
5
+ class StateYt < LicenseValidator::Validations::Base
6
+ # @see super
7
+ def validate
8
+ super
9
+
10
+ return if driver.license_num.match?(/\A\d{6}\z/i)
11
+
12
+ errors.add(
13
+ :license_num,
14
+ [
15
+ 'License number requires 6 numeric',
16
+ 'for YT'
17
+ ].join(' ')
18
+ )
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LicenseValidator
4
- VERSION = '1.3.0'
4
+ VERSION = '1.4.0'
5
5
  end
@@ -0,0 +1,74 @@
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
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.3.0
4
+ version: 1.4.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-06-02 00:00:00.000000000 Z
11
+ date: 2025-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop-rubomatic
@@ -78,10 +78,12 @@ files:
78
78
  - lib/license_validator/driver.rb
79
79
  - lib/license_validator/states.rb
80
80
  - lib/license_validator/validations/base.rb
81
+ - lib/license_validator/validations/state_ab.rb
81
82
  - lib/license_validator/validations/state_ak.rb
82
83
  - lib/license_validator/validations/state_al.rb
83
84
  - lib/license_validator/validations/state_ar.rb
84
85
  - lib/license_validator/validations/state_az.rb
86
+ - lib/license_validator/validations/state_bc.rb
85
87
  - lib/license_validator/validations/state_ca.rb
86
88
  - lib/license_validator/validations/state_co.rb
87
89
  - lib/license_validator/validations/state_ct.rb
@@ -98,6 +100,7 @@ files:
98
100
  - lib/license_validator/validations/state_ky.rb
99
101
  - lib/license_validator/validations/state_la.rb
100
102
  - lib/license_validator/validations/state_ma.rb
103
+ - lib/license_validator/validations/state_mb.rb
101
104
  - lib/license_validator/validations/state_md.rb
102
105
  - lib/license_validator/validations/state_me.rb
103
106
  - lib/license_validator/validations/state_mi.rb
@@ -105,21 +108,30 @@ files:
105
108
  - lib/license_validator/validations/state_mo.rb
106
109
  - lib/license_validator/validations/state_ms.rb
107
110
  - lib/license_validator/validations/state_mt.rb
111
+ - lib/license_validator/validations/state_nb.rb
108
112
  - lib/license_validator/validations/state_nc.rb
109
113
  - lib/license_validator/validations/state_nd.rb
110
114
  - lib/license_validator/validations/state_ne.rb
111
115
  - lib/license_validator/validations/state_nh.rb
112
116
  - lib/license_validator/validations/state_nj.rb
117
+ - lib/license_validator/validations/state_nl.rb
113
118
  - lib/license_validator/validations/state_nm.rb
119
+ - lib/license_validator/validations/state_ns.rb
120
+ - lib/license_validator/validations/state_nt.rb
121
+ - lib/license_validator/validations/state_nu.rb
114
122
  - lib/license_validator/validations/state_nv.rb
115
123
  - lib/license_validator/validations/state_ny.rb
116
124
  - lib/license_validator/validations/state_oh.rb
117
125
  - lib/license_validator/validations/state_ok.rb
126
+ - lib/license_validator/validations/state_on.rb
118
127
  - lib/license_validator/validations/state_or.rb
119
128
  - lib/license_validator/validations/state_pa.rb
129
+ - lib/license_validator/validations/state_pe.rb
130
+ - lib/license_validator/validations/state_qc.rb
120
131
  - lib/license_validator/validations/state_ri.rb
121
132
  - lib/license_validator/validations/state_sc.rb
122
133
  - lib/license_validator/validations/state_sd.rb
134
+ - lib/license_validator/validations/state_sk.rb
123
135
  - lib/license_validator/validations/state_tn.rb
124
136
  - lib/license_validator/validations/state_tx.rb
125
137
  - lib/license_validator/validations/state_ut.rb
@@ -129,8 +141,10 @@ files:
129
141
  - lib/license_validator/validations/state_wi.rb
130
142
  - lib/license_validator/validations/state_wv.rb
131
143
  - lib/license_validator/validations/state_wy.rb
144
+ - lib/license_validator/validations/state_yt.rb
132
145
  - lib/license_validator/validators.rb
133
146
  - lib/license_validator/version.rb
147
+ - lib/tasks/generator.rake
134
148
  homepage: https://github.com/brandsinsurance/license-validator/
135
149
  licenses:
136
150
  - MIT