Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mange/swedish-pin-ruby
Validate, parse, and generate Swedish Personal Identity Numbers (PINs, "Personnummer")
https://github.com/mange/swedish-pin-ruby
personnummer sweden
Last synced: 17 days ago
JSON representation
Validate, parse, and generate Swedish Personal Identity Numbers (PINs, "Personnummer")
- Host: GitHub
- URL: https://github.com/mange/swedish-pin-ruby
- Owner: Mange
- License: mit
- Created: 2020-09-08T07:26:41.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-02-03T19:14:46.000Z (almost 2 years ago)
- Last Synced: 2024-11-18T02:45:28.786Z (about 2 months ago)
- Topics: personnummer, sweden
- Language: Ruby
- Homepage:
- Size: 94.7 KB
- Stars: 4
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# swedish-pin
[![Inline docs](http://inch-ci.org/github/Mange/swedish-pin-ruby.svg?branch=master)](http://inch-ci.org/github/Mange/swedish-pin-ruby)
Validate, parse, and generate [Swedish Personal Identity
Numbers](https://en.wikipedia.org/wiki/Personal_identity_number_(Sweden))
("PINs", or *Personnummer*).[API documentation](https://www.rubydoc.info/gems/swedish-pin)
## Installation
Add this to your `Gemfile`
```ruby
gem 'swedish-pin'
```Then run `bundle install`.
## Usage
```ruby
require "swedish_pin"# Validate strings
SwedishPIN.valid?("8507099805") # => true
SwedishPIN.valid?("8507099804") # => false# Parse numbers to get more information about them, or to normalize display of
# them.
pin = SwedishPIN.parse("8507099805") # => #
pin.year # => 1985
pin.birthdate # => ## The 10-digit variant also knows about century separators.
pin.to_s # => "850709-9805"
pin.to_s(10) # => "850709-9805"
pin.format_short(Date.civil(2025, 12, 1)) # => "850709-9805"
pin.format_short(Date.civil(2085, 12, 1)) # => "850709+9805"# Use unofficial 12-digit format for a stable string that doesn't change
# depending on today's date when storing it.
pin.to_s(12) # => "19850709-9805"
pin.format_long # => "19850709-9805"# You can also generate numbers to use as example data
fake1 = SwedishPIN.generate
fake2 = SwedishPIN.generate(user.birthday)
```## License
MIT. See `LICENSE` file for more details.
This project started out as a fork of
[personnummer/ruby](https://github.com/personnummer/ruby), but has since been
almost completely rewritten.
Despite this, the original authors retains most of the copyright since this is
derivative work.