Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/c7/personnummer
Handles validation of Swedish personal identity numbers.
https://github.com/c7/personnummer
Last synced: 3 months ago
JSON representation
Handles validation of Swedish personal identity numbers.
- Host: GitHub
- URL: https://github.com/c7/personnummer
- Owner: c7
- License: mit
- Created: 2008-08-06T19:42:43.000Z (over 16 years ago)
- Default Branch: master
- Last Pushed: 2020-03-01T11:05:32.000Z (over 4 years ago)
- Last Synced: 2024-07-11T21:24:26.317Z (4 months ago)
- Language: Ruby
- Homepage:
- Size: 42 KB
- Stars: 22
- Watchers: 6
- Forks: 13
- Open Issues: 0
-
Metadata Files:
- Readme: README.markdown
- Changelog: Changelog
- License: LICENSE
Awesome Lists containing this project
- awesome-sweden - Ruby
README
# Personnummer
Personnummer is a ruby class that handles [Swedish personal identity number](http://en.wikipedia.org/wiki/Personal_identity_number_(Sweden)).
### 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)](https://www.skatteverket.se/rattsinformation/reglerochstallningstaganden/meddelanden/2010/meddelanden2010/skvm201003.5.233f91f71260075abe8800024297.html)
These numbers are obtained by adding 60 to the day of the birth date
```
>> p = Personnummer.new('830488-5912')
=> #
>> p.born
=> #
>> p.co_ordination_number?
=> true
```### Equality
```
>> p1 = Personnummer.new(8304285912)
=> #, @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](https://sv.wikipedia.org/wiki/Reservnummer#Format).