Sha256: 9a1b634ac820f7fbd811762848a0d4bfcabd1b0dbfeda60a01c29b31231ac34f
Contents?: true
Size: 681 Bytes
Versions: 1
Compression:
Stored size: 681 Bytes
Contents
module Egn class Parser def initialize(egn) return ArgumentError, 'invalid length (should == 10)' unless egn.length == 10 @year, @month, @day = egn.scan(/.{1,2}/) @month = @month.to_i @day = @day.to_i case @month when (1..12) @year = "19#{@year}" when (21..32) @month -= 20 @year = "18#{@year}" when (41..52) @month -= 40 @year = "20#{@year}" end @year = @year.to_i raise ArgumentError, "invalid date" unless Date.valid_date? @year, @month, @day end def birth_date Date.parse("#{@year}-#{@month}-#{@day}") end def gender end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
egn-0.2.0 | lib/egn/parser.rb |