henkilotunnus 1.1.0 → 1.2.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 +5 -5
- data/CHANGELOG.md +9 -0
- data/lib/henkilotunnus/hetu.rb +21 -6
- data/lib/henkilotunnus/version.rb +1 -1
- metadata +7 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 34d8b6842a081f5e71acd2582afee34b721095f71ba8fce116a90e0b8b8a9d57
|
4
|
+
data.tar.gz: 4ce7605549a9d4ef36793b0b59aacc1c0f7f43f517cb0551fca53b2c0552b489
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b2d613751cc18a5172f0a644b49160d2a25a6ab4bda357814b46ad44c80e4d950a2cebacc3b4b6c07c8372ca7ea0831400888dc2393300d23646d89b5c292c2
|
7
|
+
data.tar.gz: 2590a7d71a7c1e7a511ae50b12633fdd761a46e2055d25be95c8325368510728985a9bcc2d0e8c8f275e147fd11b5bb531905c8c436658d8780b70886a44d327
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 1.2.0 2022-10-xx
|
4
|
+
|
5
|
+
Added new punctuation marks that will be added to identity codes in 2023.
|
6
|
+
|
7
|
+
Added gender_neutral? method. Using gender methods on gender neutral
|
8
|
+
identity codes will raise an exception. Gender neutral identity codes will
|
9
|
+
be introduced in 2027. Gender methods will still be available for pins using
|
10
|
+
the old punctuation.
|
11
|
+
|
3
12
|
## 1.1.0 - 2019-04-xx
|
4
13
|
|
5
14
|
Removed the lock down from the dependent gems in order to make the gem
|
data/lib/henkilotunnus/hetu.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
module Henkilotunnus
|
2
2
|
class Hetu
|
3
3
|
GENDERS = ['female', 'male']
|
4
|
-
CENTURIES = { '+' => 1800, '-' => 1900, '
|
5
|
-
|
4
|
+
CENTURIES = { '+' => 1800, '-YXWVU' => 1900, 'ABCDEF' => 2000 }
|
5
|
+
NEW_CENTURY_SIGNS = 'YXWVUBCDEF'
|
6
|
+
PERSON_NUMBER_RANGE = 0..999
|
6
7
|
CHECKSUM_CHARS = '0123456789ABCDEFHJKLMNPRSTUVWXY'
|
7
8
|
|
8
9
|
def self.valid?(pin)
|
@@ -13,7 +14,9 @@ module Henkilotunnus
|
|
13
14
|
dob = opts.fetch(:date, Time.at(rand(Date.new(1800, 1, 1).to_time.to_i...Date.today.to_time.to_i)).to_date)
|
14
15
|
raw_dob = dob.strftime("%d%m%y")
|
15
16
|
person_number = opts.fetch(:person_number, rand(PERSON_NUMBER_RANGE)).to_s.rjust(3, "0")
|
16
|
-
|
17
|
+
century_str = CENTURIES.key(dob.year - (dob.year % 100))
|
18
|
+
sign_str_len = century_str.size - 1
|
19
|
+
century_sign = century_str[rand(0..sign_str_len)]
|
17
20
|
|
18
21
|
new(raw_dob + century_sign + person_number + compute_checksum(raw_dob, person_number))
|
19
22
|
end
|
@@ -41,7 +44,15 @@ module Henkilotunnus
|
|
41
44
|
end
|
42
45
|
|
43
46
|
def gender
|
44
|
-
|
47
|
+
if gender_neutral?
|
48
|
+
raise 'gender methods cannot be used with gender neutral identity codes. Use gender_neutral? to check.'
|
49
|
+
else
|
50
|
+
GENDERS[person_number.to_i % 2]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def gender_neutral?
|
55
|
+
(NEW_CENTURY_SIGNS.include? century_sign) && (Time.now.year > 2026)
|
45
56
|
end
|
46
57
|
|
47
58
|
def male?
|
@@ -68,7 +79,11 @@ module Henkilotunnus
|
|
68
79
|
end
|
69
80
|
|
70
81
|
def century
|
71
|
-
CENTURIES
|
82
|
+
CENTURIES.keys.each do |string|
|
83
|
+
if string.include? century_sign
|
84
|
+
return CENTURIES[string]
|
85
|
+
end
|
86
|
+
end
|
72
87
|
end
|
73
88
|
|
74
89
|
def checksum
|
@@ -90,7 +105,7 @@ module Henkilotunnus
|
|
90
105
|
end
|
91
106
|
|
92
107
|
def valid_format?
|
93
|
-
!!(pin =~ /^\d{6}[-+
|
108
|
+
!!(pin =~ /^\d{6}[-+ABCDEFYXWVU]\d{3}[0-9A-Z]$/)
|
94
109
|
end
|
95
110
|
|
96
111
|
def valid_checksum?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: henkilotunnus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Hanhikoski
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '4.2'
|
83
|
-
description:
|
83
|
+
description:
|
84
84
|
email:
|
85
85
|
- tech@pikasiirto.fi
|
86
86
|
executables: []
|
@@ -107,7 +107,7 @@ homepage: https://github.com/bittisiirto/henkilotunnus
|
|
107
107
|
licenses:
|
108
108
|
- MIT
|
109
109
|
metadata: {}
|
110
|
-
post_install_message:
|
110
|
+
post_install_message:
|
111
111
|
rdoc_options: []
|
112
112
|
require_paths:
|
113
113
|
- lib
|
@@ -122,9 +122,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
122
|
- !ruby/object:Gem::Version
|
123
123
|
version: '0'
|
124
124
|
requirements: []
|
125
|
-
|
126
|
-
|
127
|
-
signing_key:
|
125
|
+
rubygems_version: 3.2.3
|
126
|
+
signing_key:
|
128
127
|
specification_version: 4
|
129
128
|
summary: Validates Finnish personal identification numbers (henkilötunnus).
|
130
129
|
test_files: []
|