From 6e7024ec3b4e60d534bcc9ae5164ba4c7f26d9cf Mon Sep 17 00:00:00 2001 From: Ryan Johnston Date: Wed, 9 Sep 2020 10:13:05 -0400 Subject: [PATCH 1/3] Update driver license patterns according to NTSI website --- .ruby-version | 2 +- Gemfile.lock | 4 ++-- dl_validator.gemspec | 2 +- lib/config/dl_config.rb | 10 +++++----- lib/dl_validator.rb | 8 ++------ lib/dl_validator/version.rb | 2 +- test/test_helper.rb | 8 ++++---- 7 files changed, 16 insertions(+), 20 deletions(-) diff --git a/.ruby-version b/.ruby-version index 276cbf9..860487c 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.3.0 +2.7.1 diff --git a/Gemfile.lock b/Gemfile.lock index 23e5119..84fb527 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - dl_validator (0.0.7) + dl_validator (0.1.0) GEM remote: https://rubygems.org/ @@ -34,7 +34,7 @@ PLATFORMS ruby DEPENDENCIES - bundler (~> 1.3) + bundler dl_validator! rake shoulda diff --git a/dl_validator.gemspec b/dl_validator.gemspec index c9560e9..4bdfa15 100644 --- a/dl_validator.gemspec +++ b/dl_validator.gemspec @@ -18,7 +18,7 @@ Gem::Specification.new do |spec| spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ['lib'] - spec.add_development_dependency 'bundler', '~> 1.3' + spec.add_development_dependency 'bundler' spec.add_development_dependency 'rake' spec.add_development_dependency 'shoulda' spec.add_development_dependency 'test-unit' diff --git a/lib/config/dl_config.rb b/lib/config/dl_config.rb index c5d393c..998520c 100644 --- a/lib/config/dl_config.rb +++ b/lib/config/dl_config.rb @@ -58,9 +58,9 @@ class DlConfig # Constant frozen hash of regular expressions to validate a drivers license by state STATES_REGEX = { - 'AL' => /^[0-9]{1,7}$/, # Format: 1-7Numeric + 'AL' => /^[0-9]{1,8}$/, # Format: 1-8Numeric 'AK' => /^[0-9]{1,7}$/, # Format: 1-7Numeric - 'AZ' => /(^[A-Z]{1}[0-9]{1,8}$)|(^[A-Z]{2}[0-9]{2,5}$)|(^[0-9]{9}$)/, # Format: 1Alpha+1-8Numeric or 2Alpha+2-5Numeric or 9Numeric + 'AZ' => /^([A-Z]{1}[0-9]{8}|[0-9]{9})$/, # Format: 1 Alpha + 8 Numeric OR 9 Numeric 'AR' => /^[0-9]{4,9}$/, # Format: 4-9Numeric 'CA' => /^[A-Z]{1}[0-9]{7}$/, # Format: 1Alpha+7Numeric 'CO' => /(^[0-9]{9}$)|(^[A-Z]{1}[0-9]{3,6}$)|(^[A-Z]{2}[0-9]{2,5}$)/, # Format: 9Numeric or 1Alpha+3-6Numeric or 2Alpha+2-5Numeric @@ -85,12 +85,12 @@ class DlConfig 'MS' => /^[0-9]{9}$/, # Format: 9Numeric 'MO' => /(^[A-Z]{1}[0-9]{5,9}$)|(^[A-Z]{1}[0-9]{6}[R]{1}$)|(^[0-9]{8}[A-Z]{2}$)|(^[0-9]{9}[A-Z]{1}$)|(^[0-9]{9}$)/, # Format: 1Alpha+5-9Numeric or 1Alpha+6Numeric+R or 8Numeric+2Alpha or 9Numeric+1Alpha or 9Numeric 'MT' => /(^[A-Z]{1}[0-9]{8}$)|(^[0-9]{13}$)|(^[0-9]{9}$)|(^[0-9]{14}$)/, # Format: 1Alpha+8Numeric or 13Numeric or 9Numeric or 14Numeric - 'NE' => /^[0-9]{1,7}$/, # Format: 1-7Numeric + 'NE' => /^[A-Z]{1}[0-9]{6,8}$/, # Format: 1Alpha+6-8Numeric 'NV' => /(^[0-9]{9,10}$)|(^[0-9]{12}$)|(^[X]{1}[0-9]{8}$)/, # Format: 9Numeric or 10Numeric or 12Numeric or X+8Numeric 'NH' => /^[0-9]{2}[A-Z]{3}[0-9]{5}$/, # Format: 2Numeric+3Alpha+5Numeric 'NJ' => /^[A-Z]{1}[0-9]{14}$/, # Format: 1Alpha+14Numeric - 'NY' => /(^[A-Z]{1}[0-9]{7}$)|(^[A-Z]{1}[0-9]{18}$)|(^[0-9]{8}$)|(^[0-9]{9}$)|(^[0-9]{16}$)|(^[A-Z]{8}$)/, # Format: 1Alpha+7Numeric or 1Alpha+18Numeric or 8Numeric or 9Numeric or 16 Numeric or 8Alpha 'NM' => /^[0-9]{8,9}$/, # Format: 8Numeric or 9Numeric + 'NY' => /(^[A-Z]{1}[0-9]{7}$)|(^[A-Z]{1}[0-9]{18}$)|(^[0-9]{8}$)|(^[0-9]{9}$)|(^[0-9]{16}$)|(^[A-Z]{8}$)/, # Format: 1Alpha+7Numeric or 1Alpha+18Numeric or 8Numeric or 9Numeric or 16 Numeric or 8Alpha 'NC' => /^[0-9]{1,12}$/, # Format: 1-12Numeric 'ND' => /(^[A-Z]{3}[0-9]{6}$)|(^[0-9]{9}$)/, # Format: 3Alpha+6Numeric or 9Numeric 'OH' => /(^[A-Z]{1}[0-9]{4,8}$)|(^[A-Z]{2}[0-9]{3,7}$)|(^[0-9]{8}$)/, # Format: 1Alpha+4-8Numeric or 2Alpha+3-7Numeric or 8Numeric @@ -104,7 +104,7 @@ class DlConfig 'TX' => /^[0-9]{7,8}$/, # Format: 7-8Numeric 'UT' => /^[0-9]{4,10}$/, # Format: 4-10Numeric 'VT' => /(^[0-9]{8}$)|(^[0-9]{7}[A]$)/, # Format: 8Numeric or 7Numeric+A - 'VA' => /(^[A-Z]{1}[0-9]{9,11}$)|(^[0-9]{9}$)/, # Format: 1Alpha+9Numeric or 1Alpha+10Numeric or 1Alpha+11Numeric or 9Numeric + 'VA' => /(^[A-Z]{1}[0-9]{8,11}$)|(^[0-9]{9}$)/, # Format: 1Alpha+8-to-11Numeric or 9Numeric 'WA' => /^(?=.{12}$)[A-Z]{1,7}[A-Z0-9\*]{4,11}$/, # Format: 1-7Alpha+any combination of Alpha, Numeric, or * for a total of 12 characters 'WV' => /(^[0-9]{7}$)|(^[A-Z]{1,2}[0-9]{5,6}$)/, # Format: 7Numeric or 1-2Alpha+5-6Numeric 'WI' => /^[A-Z]{1}[0-9]{13}$/, # Format: 1Alpha+13Numeric diff --git a/lib/dl_validator.rb b/lib/dl_validator.rb index f3ed91d..f85673e 100644 --- a/lib/dl_validator.rb +++ b/lib/dl_validator.rb @@ -25,15 +25,11 @@ def self.invalid?(dl_number, dl_state) # This is moved out into a method to make unit testing easier. def self.get_abbreviation_key(dl_state) # If the dl_state is greater than 2 then it is a full state name and we need to find the corresponding abbreviation for that state. - key = '' if dl_state.length > 2 - DlConfig::STATES.each do |k, v| - key = k if v == dl_state - end + DlConfig::STATES.key(dl_state) else - key = dl_state # The dl_state is already an abbreviated state + dl_state # The dl_state is already an abbreviated state end - key end # Inverse of invalid? diff --git a/lib/dl_validator/version.rb b/lib/dl_validator/version.rb index 9047320..ffc4cb5 100644 --- a/lib/dl_validator/version.rb +++ b/lib/dl_validator/version.rb @@ -1,3 +1,3 @@ module DlValidator - VERSION = '0.0.7' + VERSION = '0.1.0' end diff --git a/test/test_helper.rb b/test/test_helper.rb index 8ae199f..b3ba3c0 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -5,9 +5,9 @@ class Helper VALID_DRIVERS_LICENSES = { - 'AL' => ['1234567'], # Format: 1-7Numeric + 'AL' => ['12345678'], # Format: 1-8Numeric 'AK' => ['1234567'], # Format: 1-7Numeric - 'AZ' => ['A12345678', 'AA12345', '123456789'], # Format: 1Alpha+1-8Numeric or 2Alpha+2-5Numeric or 9Numeric + 'AZ' => ['A12345678', '123456789'], # Format: 1Alpha + 8Numeric or 9Numeric 'AR' => ['1234', '123456789'], # Format: 4-9Numeric 'CA' => ['c1234567'], # Format: 1Alpha+7Numeric 'CO' => ['123456789', 'A123', 'A123456', 'AA12', 'AA12345'], # Format: 9Numeric or 1Alpha+3-6Numeric or 2Alpha+2-5Numeric @@ -32,7 +32,7 @@ class Helper 'MS' => ['123456789'], # Format: 9Numeric 'MO' => ['M12345', 'A123456789', 'M123456R' , '12345678AB', '123456789A', '123456789'], # Format: 1Alpha+5-9Numeric or 1Alpha+6Numeric+R or 8Numeric+2Alpha or 9Numeric+1Alpha or 9Numeric 'MT' => ['J12345678', '1234567890123', '123456789', '12345678901234'], # Format: 1Alpha+8Numeric or 13Numeric or 9Numeric or 14Numeric - 'NE' => ['1234567'], # Format: 1-7Numeric + 'NE' => ['A123456', 'A1234567', 'A12345678'], # Format: 1Alpha+6-8Numeric 'NV' => ['123456789', '1234567890', '123456789012', 'X12345678'], # Format: 9Numeric or 10Numeric or 12Numeric or X+8Numeric 'NH' => ['12ADF12345'], # Format: 2Numeric+3Alpha+5Numeric 'NJ' => ['F12345678901234'], # Format: 1Alpha+14Numeric @@ -51,7 +51,7 @@ class Helper 'TX' => ['1234567', '12345678'], # Format: 7-8Numeric 'UT' => ['1234', '1234567890'], # Format: 4-10Numeric 'VT' => ['12345678', '1234567A'], # Format: 8Numeric or 7Numeric+A - 'VA' => ['K123456789', 'A1234567890', 'A12345678901', '123456789'], # Format: 1Alpha+9Numeric or 1Alpha+10Numeric or 1Alpha+11Numeric or 9Numeric + 'VA' => ['A12345678', 'K123456789', 'A1234567890', 'A12345678901', '123456789'], # Format: 1Alpha+8-to-11Numeric or 9Numeric 'WA' => ['A12345678901', 'ABCDEFG12345'], # Format: 1-7Alpha+any combination of Alpha, Numeric, or * for a total of 12 characters 'WV' => ['1234567', 'E123456', 'AB123456'], # Format: 7Numeric or 1-2Alpha+5-6Numeric 'WI' => ['W1234567890123'], # Format: 1Alpha+13Numeric From 04fd088ff2bba5a0b05c6ab87207f9aaa33c23c9 Mon Sep 17 00:00:00 2001 From: Ryan Johnston Date: Wed, 9 Sep 2020 10:14:14 -0400 Subject: [PATCH 2/3] Fix indentations for comments --- lib/config/dl_config.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/config/dl_config.rb b/lib/config/dl_config.rb index 998520c..5c9cad1 100644 --- a/lib/config/dl_config.rb +++ b/lib/config/dl_config.rb @@ -73,7 +73,7 @@ class DlConfig 'ID' => /(^[A-Z]{2}[0-9]{6}[A-Z]{1}$)|(^[0-9]{9}$)/, # Format: 2Alpha+6Numeric+1Alpha or 9Numeric 'IL' => /^[A-Z]{1}[0-9]{11,12}$/, # Format: 1Alpha+11Numeric or 1Alpha+12Numeric 'IN' => /(^[A-Z]{1}[0-9]{9}$)|(^[0-9]{9,10}$)/, # Format: 1Alpha+9Numeric or 9Numeric or 10Numeric - 'IA' => /(^[0-9]{9}$)|(^[0-9]{3}[A-Z]{2}[0-9]{4})$/, # Format: 9Numeric or 3Numeric+2Alpha+4Numeric + 'IA' => /(^[0-9]{9}$)|(^[0-9]{3}[A-Z]{2}[0-9]{4})$/, # Format: 9Numeric or 3Numeric+2Alpha+4Numeric 'KS' => /(^([A-Z]{1}[0-9]{1}){2}[A-Z]{1}$)|(^[A-Z]{1}[0-9]{8}$)|(^[0-9]{9}$)/, # Format: 1Alpha+1Numeric+1Alpha+1Numeric+1Alpha or 1Alpha+8Numeric or 9Numeric 'KY' => /(^[A-Z]{1}[0-9]{8,9}$)|(^[0-9]{9}$)/, # Format: 1Alpha+8Numeric or 1Alpha+9Numeric or 9Numeric 'LA' => /^[0-9]{1,9}$/, # Format: 1-9Numeric @@ -85,7 +85,7 @@ class DlConfig 'MS' => /^[0-9]{9}$/, # Format: 9Numeric 'MO' => /(^[A-Z]{1}[0-9]{5,9}$)|(^[A-Z]{1}[0-9]{6}[R]{1}$)|(^[0-9]{8}[A-Z]{2}$)|(^[0-9]{9}[A-Z]{1}$)|(^[0-9]{9}$)/, # Format: 1Alpha+5-9Numeric or 1Alpha+6Numeric+R or 8Numeric+2Alpha or 9Numeric+1Alpha or 9Numeric 'MT' => /(^[A-Z]{1}[0-9]{8}$)|(^[0-9]{13}$)|(^[0-9]{9}$)|(^[0-9]{14}$)/, # Format: 1Alpha+8Numeric or 13Numeric or 9Numeric or 14Numeric - 'NE' => /^[A-Z]{1}[0-9]{6,8}$/, # Format: 1Alpha+6-8Numeric + 'NE' => /^[A-Z]{1}[0-9]{6,8}$/, # Format: 1Alpha+6-8Numeric 'NV' => /(^[0-9]{9,10}$)|(^[0-9]{12}$)|(^[X]{1}[0-9]{8}$)/, # Format: 9Numeric or 10Numeric or 12Numeric or X+8Numeric 'NH' => /^[0-9]{2}[A-Z]{3}[0-9]{5}$/, # Format: 2Numeric+3Alpha+5Numeric 'NJ' => /^[A-Z]{1}[0-9]{14}$/, # Format: 1Alpha+14Numeric From dc46bdea474aa1038b1179d96bc105d859141c92 Mon Sep 17 00:00:00 2001 From: Ryan Johnston Date: Wed, 9 Sep 2020 10:15:55 -0400 Subject: [PATCH 3/3] Add a link to my github in the README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 45e2a0b..b89517e 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ Andrew Medeiros, andrew@amedeiros.com, @_AndrewMedeiros ## Contributors [crstamps2](https://github.com/crstamps2) +[mrryanjohnston](https://github.com/mrryanjohnston) ## Future