henkilotunnus 1.0.2 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +29 -0
- data/henkilotunnus.gemspec +5 -5
- data/lib/henkilotunnus/hetu.rb +21 -6
- data/lib/henkilotunnus/test/person_model.rb +21 -0
- data/lib/henkilotunnus/version.rb +1 -1
- metadata +19 -18
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
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Changelog
|
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
|
+
|
12
|
+
## 1.1.0 - 2019-04-xx
|
13
|
+
|
14
|
+
Removed the lock down from the dependent gems in order to make the gem
|
15
|
+
compatible with Active Model 5.x.x and Bundler 2.x.x.
|
16
|
+
|
17
|
+
## 1.0.2 - 2018-11-14
|
18
|
+
|
19
|
+
- Added `Hetu.generate` method for valid random PIN generation
|
20
|
+
- Code cleanup and refactoring
|
21
|
+
|
22
|
+
## 1.0.1 - Unreleased
|
23
|
+
|
24
|
+
Added dependency constraints for the `minitest`, `timecop` and `activemodel`
|
25
|
+
gems.
|
26
|
+
|
27
|
+
## 1.0.0 - 2015-10-08
|
28
|
+
|
29
|
+
Initial release.
|
data/henkilotunnus.gemspec
CHANGED
@@ -18,10 +18,10 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_development_dependency "bundler", "
|
22
|
-
spec.add_development_dependency "rake", "
|
23
|
-
spec.add_development_dependency "minitest", "
|
24
|
-
spec.add_development_dependency "timecop", "
|
21
|
+
spec.add_development_dependency "bundler", ">= 1.10"
|
22
|
+
spec.add_development_dependency "rake", ">= 10.0"
|
23
|
+
spec.add_development_dependency "minitest", ">= 5.8"
|
24
|
+
spec.add_development_dependency "timecop", ">= 0.8.0"
|
25
25
|
|
26
|
-
spec.add_runtime_dependency "activemodel", "
|
26
|
+
spec.add_runtime_dependency "activemodel", ">= 4.2"
|
27
27
|
end
|
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?
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'active_model'
|
2
|
+
|
3
|
+
module Henkilotunnus
|
4
|
+
module Test
|
5
|
+
# A dummy model for testing the validator.
|
6
|
+
class PersonModel
|
7
|
+
include ActiveModel::Validations
|
8
|
+
|
9
|
+
validates :pin, hetu: true
|
10
|
+
validates :pin_message, hetu: { message: 'custom message' }
|
11
|
+
|
12
|
+
attr_reader :pin
|
13
|
+
attr_reader :pin_message
|
14
|
+
|
15
|
+
def initialize(pin)
|
16
|
+
@pin = pin
|
17
|
+
@pin_message = pin
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
metadata
CHANGED
@@ -1,86 +1,86 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: henkilotunnus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
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
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.10'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.10'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '10.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '5.8'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '5.8'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: timecop
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 0.8.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 0.8.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: activemodel
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '4.2'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
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: []
|
@@ -89,6 +89,7 @@ extra_rdoc_files: []
|
|
89
89
|
files:
|
90
90
|
- ".gitignore"
|
91
91
|
- ".travis.yml"
|
92
|
+
- CHANGELOG.md
|
92
93
|
- CODE_OF_CONDUCT.md
|
93
94
|
- Gemfile
|
94
95
|
- LICENSE.txt
|
@@ -100,12 +101,13 @@ files:
|
|
100
101
|
- lib/henkilotunnus.rb
|
101
102
|
- lib/henkilotunnus/hetu.rb
|
102
103
|
- lib/henkilotunnus/hetu_validator.rb
|
104
|
+
- lib/henkilotunnus/test/person_model.rb
|
103
105
|
- lib/henkilotunnus/version.rb
|
104
106
|
homepage: https://github.com/bittisiirto/henkilotunnus
|
105
107
|
licenses:
|
106
108
|
- MIT
|
107
109
|
metadata: {}
|
108
|
-
post_install_message:
|
110
|
+
post_install_message:
|
109
111
|
rdoc_options: []
|
110
112
|
require_paths:
|
111
113
|
- lib
|
@@ -120,9 +122,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
122
|
- !ruby/object:Gem::Version
|
121
123
|
version: '0'
|
122
124
|
requirements: []
|
123
|
-
|
124
|
-
|
125
|
-
signing_key:
|
125
|
+
rubygems_version: 3.2.3
|
126
|
+
signing_key:
|
126
127
|
specification_version: 4
|
127
128
|
summary: Validates Finnish personal identification numbers (henkilötunnus).
|
128
129
|
test_files: []
|