Class: Eid::Finland

Inherits:
Core
  • Object
show all
Defined in:
lib/eid/finland.rb

Constant Summary collapse

VALID_CENTURY_SIGNS =

NOTE: identity DDMMYYCZZZQ DDMMYY - date of birth C - century sign (+, -, U, V, W, X, Y, A, B, C, D, E, F) ZZZ - individual number (002-899 for permanent residents and Finnish citizens, 900-999 for temporary IDs) Q - control character (checksum)

%w[+ - U V W X Y A B C D E F].freeze
VALID_CONTROL_CHARACTERS =
'0123456789ABCDEFHJKLMNPRSTUVWXY'

Instance Attribute Summary

Attributes inherited from Core

#identity

Instance Method Summary collapse

Methods inherited from Core

#age, #gender, #initialize

Constructor Details

This class inherits a constructor from Eid::Core

Instance Method Details

#birth_dateObject



30
31
32
33
34
# File 'lib/eid/finland.rb', line 30

def birth_date
  Date.new(century + identity[4..5].to_i, identity[2..3].to_i, identity[0..1].to_i)
rescue StandardError
  nil
end

#female?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/eid/finland.rb', line 22

def female?
  identity[7..9].to_i.even?
end

#male?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/eid/finland.rb', line 26

def male?
  identity[7..9].to_i.odd?
end

#valid?Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
# File 'lib/eid/finland.rb', line 14

def valid?
  return false unless identity.size == 11

  birth_date.is_a?(Date) &&
    VALID_CENTURY_SIGNS.include?(identity[6]) &&
    VALID_CONTROL_CHARACTERS.include?(identity[10])
end