Class: Identification::DVLA

Inherits:
Document show all
Defined in:
lib/identification/dvla.rb

Overview

Represents a UK DVLA-issued Drivers License.

Instance Attribute Summary collapse

Attributes inherited from Document

#date_of_birth, #gender, #last_name

Instance Method Summary collapse

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.

Parameters:

  • details (Hash)

    of the paramaters

  • opts (Hash)

    a customizable set of options



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_numberObject

Returns the value of attribute driver_number.



7
8
9
# File 'lib/identification/dvla.rb', line 7

def driver_number
  @driver_number
end

#first_initialsObject

Returns the value of attribute first_initials.



7
8
9
# File 'lib/identification/dvla.rb', line 7

def first_initials
  @first_initials
end

#license_numbersObject

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

#parseBoolean

Parses MRZs and updates the instance variables. Returns true if it was successfuly parsed, false if there was an issue.

Returns:

  • (Boolean)

    whether the passport is valid or not.

Raises:

  • (RuntimeError)

    if there is no MRZ set in the instance.



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