Class: MRZ::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/mrz/result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Result

Returns a new instance of Result.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/mrz/result.rb', line 10

def initialize(opts={})
  @birth_date                  = opts.fetch(:birth_date)
  @birth_date_check_digit      = opts.fetch(:birth_date_check_digit)
  @composite_check_digit       = opts.fetch(:composite_check_digit)
  @document_code               = opts.fetch(:document_code)
  @document_number             = opts.fetch(:document_number)
  @document_number_check_digit = opts.fetch(:document_number_check_digit)
  @expiration_date             = opts.fetch(:expiration_date)
  @expiration_date_check_digit = opts.fetch(:expiration_date_check_digit)
  @first_name                  = opts.fetch(:first_name)
  @issuing_state               = opts.fetch(:issuing_state)
  @last_name                   = opts.fetch(:last_name)
  @nationality                 = opts.fetch(:nationality)
  @optional1                   = opts.fetch(:optional1)
  @optional2                   = opts.fetch(:optional2)
  @sex                         = opts.fetch(:sex)
  @type                        = opts.fetch(:type)
end

Instance Attribute Details

#birth_date_check_digitObject (readonly)

Returns the value of attribute birth_date_check_digit.



5
6
7
# File 'lib/mrz/result.rb', line 5

def birth_date_check_digit
  @birth_date_check_digit
end

#composite_check_digitObject (readonly)

Returns the value of attribute composite_check_digit.



5
6
7
# File 'lib/mrz/result.rb', line 5

def composite_check_digit
  @composite_check_digit
end

#document_codeObject (readonly)

Returns the value of attribute document_code.



5
6
7
# File 'lib/mrz/result.rb', line 5

def document_code
  @document_code
end

#document_numberObject (readonly)

Returns the value of attribute document_number.



5
6
7
# File 'lib/mrz/result.rb', line 5

def document_number
  @document_number
end

#document_number_check_digitObject (readonly)

Returns the value of attribute document_number_check_digit.



5
6
7
# File 'lib/mrz/result.rb', line 5

def document_number_check_digit
  @document_number_check_digit
end

#expiration_date_check_digitObject (readonly)

Returns the value of attribute expiration_date_check_digit.



5
6
7
# File 'lib/mrz/result.rb', line 5

def expiration_date_check_digit
  @expiration_date_check_digit
end

#first_nameObject (readonly)

Returns the value of attribute first_name.



5
6
7
# File 'lib/mrz/result.rb', line 5

def first_name
  @first_name
end

#issuing_stateObject (readonly)

Returns the value of attribute issuing_state.



5
6
7
# File 'lib/mrz/result.rb', line 5

def issuing_state
  @issuing_state
end

#last_nameObject (readonly)

Returns the value of attribute last_name.



5
6
7
# File 'lib/mrz/result.rb', line 5

def last_name
  @last_name
end

#nationalityObject (readonly)

Returns the value of attribute nationality.



5
6
7
# File 'lib/mrz/result.rb', line 5

def nationality
  @nationality
end

#optional1Object (readonly)

Returns the value of attribute optional1.



5
6
7
# File 'lib/mrz/result.rb', line 5

def optional1
  @optional1
end

#optional2Object (readonly)

Returns the value of attribute optional2.



5
6
7
# File 'lib/mrz/result.rb', line 5

def optional2
  @optional2
end

Instance Method Details

#birth_dateObject



29
30
31
32
33
34
35
36
37
# File 'lib/mrz/result.rb', line 29

def birth_date
  @_birth_date ||= begin
    year = @birth_date[0..1].to_i
    month = @birth_date[2..3].to_i
    day = @birth_date[4..5].to_i

    Date.new(add_correct_century(year), month, day)
  end
end

#expiration_dateObject



39
40
41
# File 'lib/mrz/result.rb', line 39

def expiration_date
  @_expiration_date ||= Date.strptime(@expiration_date, "%y%m%d")
end

#sexObject



43
44
45
# File 'lib/mrz/result.rb', line 43

def sex
  @_sex ||= @sex == "" ? "nonspecified" : @sex
end

#valid?Boolean

Returns:

  • (Boolean)


47
48
49
50
51
# File 'lib/mrz/result.rb', line 47

def valid?
  @_valid ||= begin
    valid_birth_date? && valid_expiration_date? && valid_document_number? && valid_composite_digit?
  end
end

#valid_birth_date?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/mrz/result.rb', line 53

def valid_birth_date?
  @_valid_birth_date ||= MRZ::CheckDigit.calculate(@birth_date).to_s == @birth_date_check_digit
end

#valid_document_number?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/mrz/result.rb', line 61

def valid_document_number?
  @_valid_document_number ||= MRZ::CheckDigit.calculate(@document_number).to_s == @document_number_check_digit
end

#valid_expiration_date?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/mrz/result.rb', line 57

def valid_expiration_date?
  @_valid_expiration_date ||= MRZ::CheckDigit.calculate(@expiration_date).to_s == @expiration_date_check_digit
end