henkilotunnus 1.0.0 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/henkilotunnus.gemspec +3 -3
- data/lib/henkilotunnus/hetu.rb +17 -3
- data/lib/henkilotunnus/hetu_validator.rb +1 -1
- data/lib/henkilotunnus/version.rb +1 -1
- data/lib/henkilotunnus.rb +1 -1
- metadata +15 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68a85f9b992b872492fe7f6375b94bcfe776da8f
|
4
|
+
data.tar.gz: fa98fb9885dd6bea7380a88ffd3c8e9912a394dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9d536638bfac999872c4b456eea519163c054d4f3f18060e263c9af2164703af2387bd9eaa2338f7427f9451cf4570589e95e7e081a6b813c75c7c1d36af1d8
|
7
|
+
data.tar.gz: e138e6c71c90df0ba38bd23eb4c511d1e50fb5f30c86ca6f0a14ddf6b9308c263a6fc34ef7ddf927c032b43a0a56ae970032e52c8549926cd58f98e71e808267
|
data/README.md
CHANGED
@@ -22,9 +22,10 @@ Hetu is a gem for validating Finnish [personal identification numbers](http://en
|
|
22
22
|
|
23
23
|
```ruby
|
24
24
|
Hetu.valid?("280264-051U")
|
25
|
+
Hetu.generate # Generate a random pin
|
25
26
|
|
26
27
|
class User < ActiveRecord
|
27
|
-
|
28
|
+
validates :pin, hetu: true
|
28
29
|
end
|
29
30
|
```
|
30
31
|
|
data/henkilotunnus.gemspec
CHANGED
@@ -20,8 +20,8 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.10"
|
22
22
|
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
-
spec.add_development_dependency "minitest"
|
24
|
-
spec.add_development_dependency "timecop"
|
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
@@ -2,12 +2,26 @@ module Henkilotunnus
|
|
2
2
|
class Hetu
|
3
3
|
GENDERS = ['female', 'male']
|
4
4
|
CENTURIES = { '+' => 1800, '-' => 1900, 'A' => 2000 }
|
5
|
+
PERSON_NUMBER_RANGE = 2..899
|
5
6
|
CHECKSUM_CHARS = '0123456789ABCDEFHJKLMNPRSTUVWXY'
|
6
7
|
|
7
8
|
def self.valid?(pin)
|
8
9
|
new(pin).valid?
|
9
10
|
end
|
10
11
|
|
12
|
+
def self.generate(opts={})
|
13
|
+
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
|
+
raw_dob = dob.strftime("%d%m%y")
|
15
|
+
person_number = opts.fetch(:person_number, rand(PERSON_NUMBER_RANGE)).to_s.rjust(3, "0")
|
16
|
+
century_sign = CENTURIES.key(dob.year - (dob.year % 100))
|
17
|
+
|
18
|
+
new(raw_dob + century_sign + person_number + compute_checksum(raw_dob, person_number))
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.compute_checksum(raw_dob, person_number)
|
22
|
+
CHECKSUM_CHARS[ (raw_dob + person_number).to_i % 31 ]
|
23
|
+
end
|
24
|
+
|
11
25
|
attr_reader :pin
|
12
26
|
|
13
27
|
def initialize(pin)
|
@@ -84,11 +98,11 @@ module Henkilotunnus
|
|
84
98
|
end
|
85
99
|
|
86
100
|
def valid_person_number?
|
87
|
-
|
101
|
+
PERSON_NUMBER_RANGE.cover?(person_number.to_i)
|
88
102
|
end
|
89
103
|
|
90
104
|
def compute_checksum
|
91
|
-
|
105
|
+
self.class.compute_checksum(raw_dob, person_number)
|
92
106
|
end
|
93
107
|
end
|
94
|
-
end
|
108
|
+
end
|
data/lib/henkilotunnus.rb
CHANGED
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.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Hanhikoski
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -42,44 +42,44 @@ dependencies:
|
|
42
42
|
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
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
|
-
version: '
|
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
|
-
version:
|
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
|
-
version:
|
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
|
-
version: '
|
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
|
-
version: '
|
82
|
+
version: '4.2'
|
83
83
|
description:
|
84
84
|
email:
|
85
85
|
- tech@pikasiirto.fi
|
@@ -121,9 +121,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
121
|
version: '0'
|
122
122
|
requirements: []
|
123
123
|
rubyforge_project:
|
124
|
-
rubygems_version: 2.
|
124
|
+
rubygems_version: 2.6.13
|
125
125
|
signing_key:
|
126
126
|
specification_version: 4
|
127
127
|
summary: Validates Finnish personal identification numbers (henkilötunnus).
|
128
128
|
test_files: []
|
129
|
-
has_rdoc:
|