0.02
No commit activity in last 3 years
No release in over 3 years
Personnummer handles validation of Swedish personal identity numbers.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

Personnummer

Personnummer is a ruby class that handles Swedish personal identity number.

Installation

$ gem install personnummer

Example usage

>> p = Personnummer.new('830428-5912')
#>>Personnummer:0x007fc971369100 @valid=true, @control_digit=2, @divider="-", @serial=591, @born=#>>PersonnummerDate:0x007fc971368318 @divider="-", @day=28, @month=4, @year=1983> #<, @region="Skaraborgs län", @female=false> #<

>> p.valid?
=> true

>> p = Personnummer.new('830428')
=> ArgumentError: The supplied personnummer is invalid

This implementation also supports co-ordination numbers

Information about co-ordination numbers (in swedish)

These numbers are obtained by adding 60 to the day of the birth date

>> p = Personnummer.new('830488-5912')
=> #<Personnummer:0x007fbafd1458d8 ...>
>> p.born
=> #<Date: 1983-04-28 ((2445453j,0s,0n),+0s,2299161j)>
>> p.co_ordination_number?
=> true

Equality

>> p1 = Personnummer.new(8304285912)
=> #<Personnummer:0x007fb8fd816588 @valid=true, @control_digit=2, @divider="-", @serial=591, @born=#<Personnummer::Born:0x007fb8fd80fa80 @divider="-", @day=28, @month=4, @year=1983>, @region="Skaraborgs län", @female=false>

>> p1 == 8304285912
=> true
p1 == '8304285912'
=> true

Note on "reservnummer"

"Reservnummer" is used in some special cases. There are only recommendations how it should be formatted, no formalized standard.

You can read more about it on wikipedia.