Sha256: 78e7b026d6215b4d6bbe1570c5a9171a7f1c0e6090b88fe82f70b3b0b8d990bc
Contents?: true
Size: 1.34 KB
Versions: 1
Compression:
Stored size: 1.34 KB
Contents
require 'dl_validator/version' require 'config/config' require 'extensions/drivers_license_invalid_validator' if defined?(Rails) module DlValidator def self.invalid?(dl_number, dl_state) # Stop and return true if either dl_number or dl_state are nil return true if dl_number.nil? or dl_state.nil? # Downcase and remove non-word characters dl_number = dl_number.to_s.upcase.gsub(/(\W|_)*/, '') dl_state = dl_state.to_s.upcase.gsub(/(\W|\d|_)*/, '') # Stop here and return true if the state does not exist return true if !Config::STATES.include?(dl_state) and !Config::STATES.values.include?(dl_state) # Find the state abbreviation key we need to access our regex hash. key = get_abbreviation_key(dl_state) # Regular expression match to validate the drivers license is invalid or not return false if Config::STATES_REGEX[key].match(dl_number) true end # 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 Config::STATES.each do |k, v| key = k if v == dl_state end else key = dl_state # The dl_state is already an abbreviated state end key end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
dl_validator-0.0.1 | lib/dl_validator.rb |