henkilotunnus 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b6b2f279df9633193233a60a17d3aab24b7813f6
4
- data.tar.gz: 7da35cc132c66d15c22376fca6a20f719e8c74a2
2
+ SHA256:
3
+ metadata.gz: 34d8b6842a081f5e71acd2582afee34b721095f71ba8fce116a90e0b8b8a9d57
4
+ data.tar.gz: 4ce7605549a9d4ef36793b0b59aacc1c0f7f43f517cb0551fca53b2c0552b489
5
5
  SHA512:
6
- metadata.gz: 7392d2a9529988b9fa5b85fdb7033dd3b08ee6f0e28df08b7171350b42bfd76f3ce86151980298eafd90f82d28ddc6b55c90d6b3ecf2d525c403f1697656a9ab
7
- data.tar.gz: 33f5e54dc518cdee0e6948a121b490d4aa13ca77435a73e4080505fa9a14e065ccf97a9a2cbcc5e9d00a9213c7df1fc5d864dfd590075141df01012a41f89a42
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
@@ -1,8 +1,9 @@
1
1
  module Henkilotunnus
2
2
  class Hetu
3
3
  GENDERS = ['female', 'male']
4
- CENTURIES = { '+' => 1800, '-' => 1900, 'A' => 2000 }
5
- PERSON_NUMBER_RANGE = 2..899
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
- century_sign = CENTURIES.key(dob.year - (dob.year % 100))
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
- GENDERS[person_number.to_i % 2]
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[century_sign]
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}[-+A]\d{3}[0-9A-Z]$/)
108
+ !!(pin =~ /^\d{6}[-+ABCDEFYXWVU]\d{3}[0-9A-Z]$/)
94
109
  end
95
110
 
96
111
  def valid_checksum?
@@ -1,3 +1,3 @@
1
1
  module Henkilotunnus
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
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.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: 2019-04-05 00:00:00.000000000 Z
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
- rubyforge_project:
126
- rubygems_version: 2.6.13
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: []