Class: Identification::Passport

Inherits:
Document
  • Object
show all
Defined in:
lib/identification/passport.rb

Overview

Represents a passport with an MRZ or fields that create an MRZ.

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 = {}) ⇒ Passport

Creates an instance of a passport. Will automatically parse if both MRZ lines are given, and will automatically generate if all necessary fields are set. (all except personal number which is rarely used)

Parameters:

  • details (Hash)

    of the paramaters

  • opts (Hash)

    a customizable set of options



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/identification/passport.rb', line 25

def initialize(params = {})
  super(params)
  @mrz_line_1 = params[:mrz_line_1]
  @mrz_line_2 = params[:mrz_line_2]
  @issuing_state = params[:issuing_state]
  @first_names = params[:first_names]
  @passport_number = params[:passport_number]
  @nationality = params[:nationality]
  @expiry_date = params[:expiry_date]
  @personal_number = params[:personal_number]

  parse if params.key?(:mrz_line_1) && params.key?(:mrz_line_2)
end

Instance Attribute Details

#expiry_dateObject

Returns the value of attribute expiry_date.



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

def expiry_date
  @expiry_date
end

#first_namesObject

Returns the value of attribute first_names.



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

def first_names
  @first_names
end

#issuing_stateObject

Returns the value of attribute issuing_state.



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

def issuing_state
  @issuing_state
end

#mrz_line_1Object

Returns the value of attribute mrz_line_1.



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

def mrz_line_1
  @mrz_line_1
end

#mrz_line_2Object

Returns the value of attribute mrz_line_2.



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

def mrz_line_2
  @mrz_line_2
end

#nationalityObject

Returns the value of attribute nationality.



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

def nationality
  @nationality
end

#passport_numberObject

Returns the value of attribute passport_number.



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

def passport_number
  @passport_number
end

#personal_numberObject

Returns the value of attribute personal_number.



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

def personal_number
  @personal_number
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.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/identification/passport.rb', line 44

def parse
  if !@mrz_line_1.nil? && !@mrz_line_2.nil?
    result = Parser::Passport.parse(@mrz_line_1, @mrz_line_2)
    @issuing_state = result[:issuing_state] if result.key?(:issuing_state)
    @last_name = result[:last_name] if result.key?(:last_name)
    @first_names = result[:first_names] if result.key?(:first_names)
    @passport_number = result[:passport_number] if result.key?(:passport_number)
    @nationality = result[:nationality] if result.key?(:nationality)
    @date_of_birth = result[:date_of_birth] if result.key?(:date_of_birth)
    @gender = result[:gender] if result.key?(:gender)
    @expiry_date = result[:expiry_date] if result.key?(:expiry_date)
    @personal_number = result[:personal_number] if result.key?(:personal_number)
    @validity = result[:validity]
    return true if @validity
  else
    fail 'No MRZ set to parse.'
  end

  false
end