license-validator 1.0.0.pre.rc.1 → 1.0.1.pre.rc.1

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: caf6ea101c3510f78fa8fbf1706440efc19f35b127cfe17548e75ffb318a82aa
4
+ data.tar.gz: d421d36045261f2a2a2511b52b70154d5ff0827fe22c40445f6c432fe07d184a
5
5
  SHA512:
6
- metadata.gz: ec6ce697e9fd2fd393857ae643f6bc136adb8be738f41327ca7ecbc12208d8b92d7f979cfb9576432360f835319b428afd3778e8794256a535d8d816f015b7fc
7
- data.tar.gz: 9b346187ac19b067622d7d8b691488093779bac7e39ff6177e8bd94c305744e0bb5d36f96292c2d5533570e84813f16e287e0754b1b52c2aa4e5d84753514a9e
6
+ metadata.gz: 9c246727a3c6bc3334618b0c2e1de468de81af0bd9dcab6b8adf6c572f31036325e5b6b6fba43436ae7600850b0ce749824671bc9f328f1791196e0260e09ca3
7
+ data.tar.gz: 1833b407af5ac22b46c9e3b6291b3dd655a212667b37e762b7c4e61e39eec96ab6e352e2c5242d219ecd5a0cf554bce0bf36bc11bb71bcd490c9303d7fd642cb
@@ -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,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 [LicenseValidator::Driver]
13
- attr_accessor :driver
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?
@@ -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.1-rc.1'
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.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-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