swedish-pin 1.1.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +33 -0
- data/CHANGELOG.md +30 -1
- data/Gemfile.lock +27 -26
- data/LICENSE +1 -1
- data/README.md +1 -1
- data/bin/standardrb +29 -0
- data/lib/swedish_pin/generator.rb +10 -10
- data/lib/swedish_pin/parser.rb +20 -9
- data/lib/swedish_pin/personnummer.rb +3 -1
- data/lib/swedish_pin/version.rb +1 -1
- data/lib/swedish_pin.rb +1 -1
- data/personnummer.gemspec +1 -3
- metadata +6 -33
- data/.travis.yml +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8dd38e3a23539a5d2c44a2f47dca405748640377ff60f4f5f64359ccf78739b2
|
4
|
+
data.tar.gz: c03e1cd7d9d34ab5739a5e9e7647621138c3a7cb7e0ef8c9d12cd14d0ae28b57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c44152a32e0f99508dd754ab975e7bf8bb28dc5029c6d37f0f193edf82c7b0a410807c00e9beee2a8377fd3acc295ee4a5b15453dc3f9783151c9d9d0fa9df2
|
7
|
+
data.tar.gz: 13f23fd9dac7c68c6dc2227a7ada375f4ed335d1caf3f42496cf947932054e39c5b0a71c5a1183b55d6a13160071aefe0a9c402ef5a91d7bdc96ca52d95ba803
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# yaml-language-server: $schema=https://github.com/SchemaStore/schemastore/raw/master/src/schemas/json/github-workflow.json
|
2
|
+
name: CI
|
3
|
+
|
4
|
+
on: [push, pull_request]
|
5
|
+
|
6
|
+
jobs:
|
7
|
+
lint:
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
steps:
|
10
|
+
- uses: actions/checkout@v3
|
11
|
+
- uses: ruby/setup-ruby@v1
|
12
|
+
with:
|
13
|
+
ruby-version: "2.7"
|
14
|
+
bundler-cache: true
|
15
|
+
- run: bundle exec standardrb --no-fix
|
16
|
+
|
17
|
+
tests:
|
18
|
+
strategy:
|
19
|
+
fail-fast: false
|
20
|
+
matrix:
|
21
|
+
os: [ubuntu-latest]
|
22
|
+
# Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
|
23
|
+
ruby: ["2.7", "3.0", "3.1", "3.2"]
|
24
|
+
|
25
|
+
runs-on: ${{ matrix.os }}
|
26
|
+
|
27
|
+
steps:
|
28
|
+
- uses: actions/checkout@v3
|
29
|
+
- uses: ruby/setup-ruby@v1
|
30
|
+
with:
|
31
|
+
ruby-version: ${{ matrix.ruby }}
|
32
|
+
bundler-cache: true
|
33
|
+
- run: rake
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,34 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
Nothing yet.
|
11
|
+
|
12
|
+
## [2.0.0] - 2023-01-11
|
13
|
+
|
14
|
+
### Breaking changes
|
15
|
+
|
16
|
+
* Minimum supported Ruby version bumped from 2.5 to 2.7.
|
17
|
+
|
18
|
+
### Fixed
|
19
|
+
|
20
|
+
* PINs with future birthdates are now parsed as long as they are for the
|
21
|
+
current year.
|
22
|
+
* **Example:** `20xyab-nnnn` used to be parsed as `1920` until `2020-xy-ab`,
|
23
|
+
but now it's parsed as `2020` from 2020-01-01 and onwards. This is more
|
24
|
+
correct, since all 1920s PINs should be written with a `+` after
|
25
|
+
2020-01-01.
|
26
|
+
* Parsing of 10-digit PINs were improved so it is always consistent so
|
27
|
+
`parse(pin.to_s(10)) == pin`.
|
28
|
+
|
29
|
+
### Removed
|
30
|
+
|
31
|
+
* Explicit installation of `rake` and `minitest` as development dependencies
|
32
|
+
removed. Now relying on the versions bundled with Ruby.
|
33
|
+
|
34
|
+
### Other
|
35
|
+
|
36
|
+
* Travis CI setup changed into Github Actions.
|
37
|
+
|
10
38
|
## [1.1.0] - 2022-07-04
|
11
39
|
|
12
40
|
### Fixed
|
@@ -22,6 +50,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
22
50
|
|
23
51
|
Initial release.
|
24
52
|
|
25
|
-
[Unreleased]: https://github.com/Mange/swedish-pin-ruby/compare/v1.0.0...HEAD
|
26
53
|
[1.0.0]: https://github.com/Mange/swedish-pin-ruby/releases/tag/v1.0.0
|
27
54
|
[1.1.0]: https://github.com/Mange/swedish-pin-ruby/releases/tag/v1.1.0
|
55
|
+
[2.0.0]: https://github.com/Mange/swedish-pin-ruby/releases/tag/v2.0.0
|
56
|
+
[Unreleased]: https://github.com/Mange/swedish-pin-ruby/compare/v2.0.0...HEAD
|
data/Gemfile.lock
CHANGED
@@ -1,45 +1,46 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
swedish-pin (
|
4
|
+
swedish-pin (2.0.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
ast (2.4.
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
ast (2.4.2)
|
10
|
+
json (2.6.3)
|
11
|
+
language_server-protocol (3.17.0.2)
|
12
|
+
parallel (1.22.1)
|
13
|
+
parser (3.2.0.0)
|
13
14
|
ast (~> 2.4.1)
|
14
|
-
rainbow (3.
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
rainbow (3.1.1)
|
16
|
+
regexp_parser (2.6.1)
|
17
|
+
rexml (3.2.5)
|
18
|
+
rubocop (1.42.0)
|
19
|
+
json (~> 2.3)
|
19
20
|
parallel (~> 1.10)
|
20
|
-
parser (>=
|
21
|
+
parser (>= 3.1.2.1)
|
21
22
|
rainbow (>= 2.2.2, < 4.0)
|
22
|
-
regexp_parser (>= 1.
|
23
|
-
rexml
|
24
|
-
rubocop-ast (>=
|
23
|
+
regexp_parser (>= 1.8, < 3.0)
|
24
|
+
rexml (>= 3.2.5, < 4.0)
|
25
|
+
rubocop-ast (>= 1.24.1, < 2.0)
|
25
26
|
ruby-progressbar (~> 1.7)
|
26
|
-
unicode-display_width (>= 1.4.0, <
|
27
|
-
rubocop-ast (
|
28
|
-
parser (>=
|
29
|
-
rubocop-performance (1.
|
30
|
-
rubocop (>=
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
27
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
28
|
+
rubocop-ast (1.24.1)
|
29
|
+
parser (>= 3.1.1.0)
|
30
|
+
rubocop-performance (1.15.2)
|
31
|
+
rubocop (>= 1.7.0, < 2.0)
|
32
|
+
rubocop-ast (>= 0.4.0)
|
33
|
+
ruby-progressbar (1.11.0)
|
34
|
+
standard (1.21.1)
|
35
|
+
language_server-protocol (~> 3.17.0.2)
|
36
|
+
rubocop (= 1.42.0)
|
37
|
+
rubocop-performance (= 1.15.2)
|
38
|
+
unicode-display_width (2.4.2)
|
36
39
|
|
37
40
|
PLATFORMS
|
38
41
|
ruby
|
39
42
|
|
40
43
|
DEPENDENCIES
|
41
|
-
minitest
|
42
|
-
rake
|
43
44
|
standard
|
44
45
|
swedish-pin!
|
45
46
|
|
data/LICENSE
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
MIT License
|
2
2
|
|
3
|
-
Copyright (c) 2017-
|
3
|
+
Copyright (c) 2017-2022 - Personnummer, Magnus Bergmark and Contributors
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# swedish-pin
|
2
2
|
|
3
|
-
[](http://inch-ci.org/github/Mange/swedish-pin-ruby)
|
4
4
|
|
5
5
|
Validate, parse, and generate [Swedish Personal Identity
|
6
6
|
Numbers](https://en.wikipedia.org/wiki/Personal_identity_number_(Sweden))
|
data/bin/standardrb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'standardrb' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("standard", "standardrb")
|
@@ -8,37 +8,37 @@ module SwedishPIN
|
|
8
8
|
#
|
9
9
|
# Generator for PINs.
|
10
10
|
class Generator
|
11
|
-
# The date all generated PINs will be based on.
|
12
|
-
attr_reader :date
|
13
|
-
|
14
11
|
# Creates a new generator for a particular date.
|
15
|
-
def initialize(
|
16
|
-
@
|
12
|
+
def initialize(random: Random)
|
13
|
+
@random = random
|
17
14
|
end
|
18
15
|
|
19
16
|
# Generate a {Personnummer} with the given sequence number.
|
20
|
-
def generate(sequence_number)
|
17
|
+
def generate(date: random_date, sequence_number: random_sequence_number)
|
18
|
+
# Handle someone explicitly passing `nil`.
|
19
|
+
date ||= random_date
|
21
20
|
sequence_number ||= random_sequence_number
|
21
|
+
|
22
22
|
Personnummer.new(
|
23
23
|
year: date.year,
|
24
24
|
month: date.month,
|
25
25
|
day: date.day,
|
26
26
|
sequence_number: sequence_number,
|
27
|
-
control_digit: control_digit(sequence_number)
|
27
|
+
control_digit: control_digit(date, sequence_number)
|
28
28
|
)
|
29
29
|
end
|
30
30
|
|
31
31
|
private
|
32
32
|
|
33
33
|
def random_date
|
34
|
-
Date.today -
|
34
|
+
Date.today - @random.rand(0..(110 * 365))
|
35
35
|
end
|
36
36
|
|
37
37
|
def random_sequence_number
|
38
|
-
|
38
|
+
@random.rand(0..999)
|
39
39
|
end
|
40
40
|
|
41
|
-
def control_digit(sequence_number)
|
41
|
+
def control_digit(date, sequence_number)
|
42
42
|
padded = ("%03d" % sequence_number)
|
43
43
|
SwedishPIN.luhn("#{date.strftime("%y%m%d")}#{padded}")
|
44
44
|
end
|
data/lib/swedish_pin/parser.rb
CHANGED
@@ -17,7 +17,7 @@ module SwedishPIN
|
|
17
17
|
(?<sequence_number>\d{3})
|
18
18
|
(?<control_digit>\d)
|
19
19
|
\z
|
20
|
-
/x
|
20
|
+
/x
|
21
21
|
private_constant :MATCHER
|
22
22
|
|
23
23
|
# Setup a new parser.
|
@@ -105,19 +105,30 @@ module SwedishPIN
|
|
105
105
|
end
|
106
106
|
|
107
107
|
def guess_century
|
108
|
-
|
109
|
-
|
110
|
-
#
|
111
|
-
|
112
|
-
|
108
|
+
century = now.year / 100
|
109
|
+
|
110
|
+
# Century could take up to three different values, depending on
|
111
|
+
# combination of "future" dates and `+` separators.
|
112
|
+
#
|
113
|
+
# For example, on year 2010:
|
114
|
+
# 100101-nnnn => 2010-01-01
|
115
|
+
# 110101-nnnn => 1911-01-01 (because 2011 has not happened yet)
|
116
|
+
# 110101+nnnn => 1811-01-01 (1911 - 100 years)
|
117
|
+
# 090101+nnnn => 1909-01-01 (2009 - 100 years)
|
118
|
+
#
|
119
|
+
# One step comes from using the `+` separator, which means "remove
|
120
|
+
# another 100 years", despite what the rest of the date seems to imply.
|
121
|
+
|
122
|
+
# Assume previous century on future years
|
123
|
+
if (century * 100) + year > now.year
|
124
|
+
century -= 1
|
113
125
|
end
|
114
126
|
|
115
|
-
# The "+" separator means another century back.
|
116
127
|
if @matches["separator"] == "+"
|
117
|
-
|
128
|
+
century -= 1
|
118
129
|
end
|
119
130
|
|
120
|
-
|
131
|
+
century
|
121
132
|
end
|
122
133
|
|
123
134
|
def validate_match
|
@@ -44,7 +44,7 @@ module SwedishPIN
|
|
44
44
|
@year = year
|
45
45
|
@month = month
|
46
46
|
@coordination_number = day > 60
|
47
|
-
@day = (day > 60 ? day - 60 : day)
|
47
|
+
@day = ((day > 60) ? day - 60 : day)
|
48
48
|
@sequence_number = sequence_number
|
49
49
|
@control_digit = control_digit
|
50
50
|
end
|
@@ -201,6 +201,8 @@ module SwedishPIN
|
|
201
201
|
private
|
202
202
|
|
203
203
|
def short_separator(now)
|
204
|
+
# Turn into `+` on the same year as the PINs 100th birthday, even before
|
205
|
+
# the actual date.
|
204
206
|
if year <= (now.year - 100)
|
205
207
|
"+"
|
206
208
|
else
|
data/lib/swedish_pin/version.rb
CHANGED
data/lib/swedish_pin.rb
CHANGED
@@ -81,7 +81,7 @@ module SwedishPIN
|
|
81
81
|
# @param [Date, Time, nil] birthday The birthday of the person the PIN identifies, or +nil+ for a random date in the past.
|
82
82
|
# @param [String, Integer, nil] sequence_number The sequence number that correspond to the three digits after the birthday, or +nil+ to pick a random one.
|
83
83
|
def self.generate(birthday = nil, sequence_number = nil)
|
84
|
-
Generator.new
|
84
|
+
Generator.new.generate(date: birthday, sequence_number: sequence_number)
|
85
85
|
end
|
86
86
|
|
87
87
|
# @api private
|
data/personnummer.gemspec
CHANGED
@@ -3,7 +3,7 @@ require_relative "lib/swedish_pin/version"
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "swedish-pin"
|
5
5
|
s.version = SwedishPIN::VERSION
|
6
|
-
s.required_ruby_version = Gem::Requirement.new(">= 2.
|
6
|
+
s.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
|
7
7
|
|
8
8
|
s.license = "MIT"
|
9
9
|
s.summary = "Work with Swedish PINs (Personnummer)"
|
@@ -22,7 +22,5 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
23
|
s.require_paths = ["lib"]
|
24
24
|
|
25
|
-
s.add_development_dependency "rake"
|
26
|
-
s.add_development_dependency "minitest"
|
27
25
|
s.add_development_dependency "standard"
|
28
26
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swedish-pin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Magnus Bergmark
|
@@ -10,36 +10,8 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2023-01-11 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
|
-
- !ruby/object:Gem::Dependency
|
16
|
-
name: rake
|
17
|
-
requirement: !ruby/object:Gem::Requirement
|
18
|
-
requirements:
|
19
|
-
- - ">="
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '0'
|
22
|
-
type: :development
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
requirements:
|
26
|
-
- - ">="
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
version: '0'
|
29
|
-
- !ruby/object:Gem::Dependency
|
30
|
-
name: minitest
|
31
|
-
requirement: !ruby/object:Gem::Requirement
|
32
|
-
requirements:
|
33
|
-
- - ">="
|
34
|
-
- !ruby/object:Gem::Version
|
35
|
-
version: '0'
|
36
|
-
type: :development
|
37
|
-
prerelease: false
|
38
|
-
version_requirements: !ruby/object:Gem::Requirement
|
39
|
-
requirements:
|
40
|
-
- - ">="
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
version: '0'
|
43
15
|
- !ruby/object:Gem::Dependency
|
44
16
|
name: standard
|
45
17
|
requirement: !ruby/object:Gem::Requirement
|
@@ -64,15 +36,16 @@ executables: []
|
|
64
36
|
extensions: []
|
65
37
|
extra_rdoc_files: []
|
66
38
|
files:
|
39
|
+
- ".github/workflows/ci.yml"
|
67
40
|
- ".gitignore"
|
68
41
|
- ".solargraph.yml"
|
69
|
-
- ".travis.yml"
|
70
42
|
- CHANGELOG.md
|
71
43
|
- Gemfile
|
72
44
|
- Gemfile.lock
|
73
45
|
- LICENSE
|
74
46
|
- README.md
|
75
47
|
- Rakefile
|
48
|
+
- bin/standardrb
|
76
49
|
- lib/swedish-pin.rb
|
77
50
|
- lib/swedish_pin.rb
|
78
51
|
- lib/swedish_pin/errors.rb
|
@@ -93,14 +66,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
93
66
|
requirements:
|
94
67
|
- - ">="
|
95
68
|
- !ruby/object:Gem::Version
|
96
|
-
version: 2.
|
69
|
+
version: 2.7.0
|
97
70
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
71
|
requirements:
|
99
72
|
- - ">="
|
100
73
|
- !ruby/object:Gem::Version
|
101
74
|
version: '0'
|
102
75
|
requirements: []
|
103
|
-
rubygems_version: 3.
|
76
|
+
rubygems_version: 3.3.7
|
104
77
|
signing_key:
|
105
78
|
specification_version: 4
|
106
79
|
summary: Work with Swedish PINs (Personnummer)
|