require 'identification/document' require 'identification/parser/dvla' module Identification # Represents a UK DVLA-issued Drivers License. class DVLA < Document attr_accessor :driver_number, :first_initials, :license_numbers # 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. # # @param [Hash] details of the paramaters # @option opts [String] :driver_number 18 digit driver number, section 5 on a drivers license of the individual (only set for parsing) # @option opts [String] :first_initials first initials of the individual (only set for generating) # @option opts [String] :last_name surname of the individual - this will be abridged to the first 5 letters only (only set for generating) # @option opts [String] :date_of_birth date of birth of the individual (only set for generating) # @option opts [String] :gender gender of the individual stored as M or F (only set for generating) # @option opts [String] :license_numbers license number of the passport (only set for generating) 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 # Parses MRZs and updates the instance variables. # Returns true if it was successfuly parsed, false if there was an issue. # # @return [Boolean] whether the passport is valid or not. # @raise [RuntimeError] if there is no MRZ set in the instance. 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 end end