Class: KuwaitiCivilId::BirthdateExtractor

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

Class Method Summary collapse

Class Method Details

.extract(id_number) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/kuwaiti_civil_id.rb', line 23

def self.extract(id_number)
  raise InvalidCivilIdError unless CivilIdValidator.valid?(id_number)

  century = id_number[0].to_i
  year = id_number[1..2].to_i
  month = id_number[3..4].to_i
  day = id_number[5..6].to_i

  century_prefix = case century
                   when 2 then "19"
                   when 3 then "20"
                   else return nil
                   end

  year = "#{century_prefix}#{year}".to_i
  Date.new(year, month, day)
end