Class: Identification::DVLA
- Defined in:
- lib/identification/dvla.rb
Overview
Represents a UK DVLA-issued Drivers License.
Instance Attribute Summary collapse
-
#driver_number ⇒ Object
Returns the value of attribute driver_number.
-
#first_initials ⇒ Object
Returns the value of attribute first_initials.
-
#license_numbers ⇒ Object
Returns the value of attribute license_numbers.
Attributes inherited from Document
#date_of_birth, #gender, #last_name
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ DVLA
constructor
Creates an instance of a drivers license.
-
#parse ⇒ Boolean
Parses MRZs and updates the instance variables.
Methods inherited from Document
#age, #over_18?, #over_21?, #valid?
Constructor Details
#initialize(params = {}) ⇒ DVLA
Creates an instance of a drivers license. Will automatically parse if the drivers number is given, and will automatically generate if all necessary fields are set.
19 20 21 22 23 24 25 |
# File 'lib/identification/dvla.rb', line 19 def initialize(params = {}) super(params) @driver_number = params[:driver_number] @first_initials = params[:first_initials] @license_numbers = params[:license_numbers] parse if params.key?(:driver_number) end |
Instance Attribute Details
#driver_number ⇒ Object
Returns the value of attribute driver_number.
7 8 9 |
# File 'lib/identification/dvla.rb', line 7 def driver_number @driver_number end |
#first_initials ⇒ Object
Returns the value of attribute first_initials.
7 8 9 |
# File 'lib/identification/dvla.rb', line 7 def first_initials @first_initials end |
#license_numbers ⇒ Object
Returns the value of attribute license_numbers.
7 8 9 |
# File 'lib/identification/dvla.rb', line 7 def license_numbers @license_numbers end |
Instance Method Details
#parse ⇒ Boolean
Parses MRZs and updates the instance variables. Returns true if it was successfuly parsed, false if there was an issue.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/identification/dvla.rb', line 32 def parse if !@driver_number.nil? result = Parser::DVLA.parse(@driver_number) @last_name = result[:last_name] if result.key?(:last_name) @first_initials = result[:first_initials] if result.key?(:first_initials) @date_of_birth = result[:date_of_birth] if result.key?(:date_of_birth) @license_numbers = result[:license_numbers] if result.key?(:license_numbers) @gender = result[:gender] if result.key?(:gender) @validity = result[:validity] return true if @validity else fail 'No drivers number set to parse.' end false end |