license-validator 1.0.0.pre.rc.1 → 1.0.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: 8fe7ae2eee4e5a9431670aa6db06aaa0de42016ac56fc2637ff8ff5ea87b238f
4
- data.tar.gz: f846963096f33090ce563ed7f27d1b18d0ff4a19caa9420a9c6cc70f04248e80
3
+ metadata.gz: 765d257c1c164253fc920091c417c0b23315ddee7e4d1be7cf2b53d0afa31e53
4
+ data.tar.gz: 9cdb4da632bdacc45fdeec2b0532e9b747f0b92f60646cf3f2779af52f6520a8
5
5
  SHA512:
6
- metadata.gz: ec6ce697e9fd2fd393857ae643f6bc136adb8be738f41327ca7ecbc12208d8b92d7f979cfb9576432360f835319b428afd3778e8794256a535d8d816f015b7fc
7
- data.tar.gz: 9b346187ac19b067622d7d8b691488093779bac7e39ff6177e8bd94c305744e0bb5d36f96292c2d5533570e84813f16e287e0754b1b52c2aa4e5d84753514a9e
6
+ metadata.gz: 8397c4a34805f88648398cf4a2e9787255b803413f88e13c37d4d2aa81d99df5b4b9c5544bb5b6f938d7d5afc51515d891d232f5a4d300af8b858856f91449f1
7
+ data.tar.gz: 273c364371d31a1810e29446786c46326b1385438a58cad2448ec61ecf170564f71e2b34da9e7467b0bd01ea98d837cda73d330408df39292cdf6072b0916f72
@@ -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 :license_num, presence: true
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 [String]
24
- attr_accessor :license_num
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 [Boolean]
30
- attr_accessor :bad
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 [LicenseValidator::Driver]
13
- attr_accessor :driver
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)
@@ -10,7 +10,9 @@ module LicenseValidator
10
10
  lic_num = driver.license_num
11
11
 
12
12
  return if lic_num.match?(/\A\d{7,8}\z/i)
13
+
13
14
  return if lic_num.match?(/\A[a-z]\d{6,8}\z/i)
15
+
14
16
  return if lic_num.match?(/\AID\d{5,6}\z/i)
15
17
 
16
18
  errors.add(
@@ -22,6 +22,7 @@ module LicenseValidator
22
22
  lic_num = driver.license_num
23
23
 
24
24
  return if lic_num.match?(/\A[a-z]\d{8}\z/i)
25
+
25
26
  return if lic_num.match?(/\A\d{9}\z/i)
26
27
 
27
28
  errors.add(:license_num, 'License number requires 1 Alphabetic, 8 Numeric or 9 Numeric for AZ.')
@@ -14,6 +14,7 @@ module LicenseValidator
14
14
  lic_num = driver.license_num
15
15
 
16
16
  return if lic_num.match?(/\A\d{9}\z/i)
17
+
17
18
  return if lic_num.match?(/\A[a-z]\d{3,6}\z/i)
18
19
 
19
20
  errors.add(:license_num, 'License number requires 9 numeric or 1 alphabetic, 3-6 numeric for CO.')
@@ -22,7 +22,9 @@ module LicenseValidator
22
22
 
23
23
  year = driver.dob.year
24
24
  month = driver.dob.month
25
+
25
26
  month += 12 if year.even?
27
+
26
28
  month = "#{0 if month < 10}#{month}"
27
29
 
28
30
  regex = Regexp.new("\\A#{month}\\d{7}\\z", 'i')
@@ -18,6 +18,7 @@ module LicenseValidator
18
18
  lic_num = driver.license_num
19
19
 
20
20
  return if lic_num.match?(/\A\d{9}\z/i)
21
+
21
22
  return if lic_num.match?(/\AH\d{8}\z/i)
22
23
 
23
24
  errors.add(:license_num, 'License number needs 9 numeric or "H", 8 numeric for HI.')
@@ -10,6 +10,7 @@ module LicenseValidator
10
10
  lic_num = driver.license_num
11
11
 
12
12
  return if lic_num.match?(/\A\d{3}[a-z]{2}\d{4}\z/i)
13
+
13
14
  return if lic_num.match?(/\A\d{9}\z/i)
14
15
 
15
16
  errors.add(
@@ -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,6 +10,7 @@ module LicenseValidator
10
10
  lic_num = driver.license_num
11
11
 
12
12
  return if lic_num.match?(/\A[a-z]\d{8}\z/i)
13
+
13
14
  return if lic_num.match?(/\A\d{9}\z/i)
14
15
 
15
16
  errors.add(:license_num, 'License number requires 1 alphabetic and 8 numeric, or 9 numeric for KY.')
@@ -10,6 +10,7 @@ module LicenseValidator
10
10
  lic_num = driver.license_num
11
11
 
12
12
  return if lic_num.match?(/\A[b-z]\d{8}\z/i)
13
+
13
14
  return if lic_num.match?(/\A[a-z]{2}\d{7}\z/i) && !lic_num.match?(/\Afr\d{7}\z/i)
14
15
 
15
16
  errors.add(
@@ -10,6 +10,7 @@ module LicenseValidator
10
10
  lic_num = driver.license_num
11
11
 
12
12
  return if lic_num.match?(/\A[a-z]\d{12}\z/i)
13
+
13
14
  return if lic_num.match?(/\A[a-z]{2}\d{11}\z/i)
14
15
 
15
16
  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{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,6 +10,7 @@ module LicenseValidator
10
10
  lic_num = driver.license_num
11
11
 
12
12
  return if lic_num.match?(/\A\d{9}\z/i)
13
+
13
14
  return if lic_num.match?(/\A[a-z]{3}\d{6}\z/i)
14
15
 
15
16
  errors.add(:license_num, 'License number reuqires 9 Numeric or 3 Alphabetic, 6 Numeric for ND.')
@@ -18,6 +18,7 @@ module LicenseValidator
18
18
  lic_num = driver.license_num
19
19
 
20
20
  return if lic_num.match?(/\A\d{2}[a-z]{3}\d{5}\z/i)
21
+
21
22
  return if lic_num.match?(/\ANHL\d{8}\z/i)
22
23
 
23
24
  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(
@@ -10,6 +10,7 @@ module LicenseValidator
10
10
  lic_num = driver.license_num
11
11
 
12
12
  return if lic_num.match?(/\A[a-z]{2}\d{6}\z/i)
13
+
13
14
  return if lic_num.match?(/\A\d{9}\z/i)
14
15
 
15
16
  errors.add(:license_num, 'License number requires 2 Alphabetic, 6 Numeric or 9 Numeric for OH.')
@@ -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.')
@@ -10,6 +10,7 @@ module LicenseValidator
10
10
  lic_num = driver.license_num
11
11
 
12
12
  return if lic_num.match?(/\A\d{7,8}\z/i)
13
+
13
14
  return if lic_num.match?(/\AV\d{6}\z/i)
14
15
 
15
16
  errors.add(:license_num, 'License number requires 8 numeric or 7 Numeric or V and 6 Numeric for RI.')
@@ -10,6 +10,7 @@ module LicenseValidator
10
10
  lic_num = driver.license_num
11
11
 
12
12
  return if lic_num.match?(/\A\d{6}\z/i)
13
+
13
14
  return if lic_num.match?(/\A\d{8,9}\z/i)
14
15
 
15
16
  errors.add(:license_num, 'License number requires 6,8, or 9 numbers for SD.')
@@ -14,6 +14,7 @@ module LicenseValidator
14
14
  lic_num = driver.license_num
15
15
 
16
16
  return if lic_num.match?(/\A\d{7}\z/i)
17
+
17
18
  return if lic_num.match?(/\A[01a-z][a-z]?\d{5,6}\z/i)
18
19
 
19
20
  errors.add(
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- Dir[File.expand_path('validations/*.rb', __dir__)].each do |filename|
3
+ Dir[File.expand_path('validations/*.rb', __dir__)].sort.each do |filename|
4
4
  require filename
5
5
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LicenseValidator
4
- VERSION = '1.0.0-rc.1'
4
+ VERSION = '1.0.0'
5
5
  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.0.0.pre.rc.1
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-30 00:00:00.000000000 Z
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: 1.3.1
143
+ version: '0'
144
144
  requirements: []
145
145
  rubygems_version: 3.4.10
146
146
  signing_key: