resident 0.0.15 → 0.0.17
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f4020e94bb0aff9861d0fdf6dfc97246ed2e99e3861a1b5a82a448e78eb2dbe5
|
|
4
|
+
data.tar.gz: 166917cbc7910e024ce24c36f0e01b4c3616184425e9ff52b8efea519b4750d6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c12c81772f4cacfd32a04da14ae7ace2dc2ea30fba94912a3edd3f146b4122032c8c576fb71b55e74673934ade5afc4f39d53cd5bc2d0f05bd8e60f6174179b9
|
|
7
|
+
data.tar.gz: d9bb2c179845a3a4819ee8a984204267b81bb463dd25ee549a887e19eb65249f791350ad235075f4ddcdcb32ce3ecaeef03f754a4b0f17bfa61e35ac017f0e3a
|
|
@@ -17,9 +17,11 @@ module NationalIdentificationNumber
|
|
|
17
17
|
|
|
18
18
|
sans_checksum = "#{day}#{month}#{year}#{serial}"
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
birth_century = century(serial.to_i, year.to_i)
|
|
21
|
+
|
|
22
|
+
if birth_century && checksum == calculate_checksum(sans_checksum)
|
|
21
23
|
begin
|
|
22
|
-
@date = Date.parse("#{
|
|
24
|
+
@date = Date.parse("#{birth_century + year.to_i}-#{month}-#{day}")
|
|
23
25
|
@valid = true
|
|
24
26
|
@number = "#{sans_checksum}#{checksum}"
|
|
25
27
|
rescue ArgumentError
|
|
@@ -30,15 +32,13 @@ module NationalIdentificationNumber
|
|
|
30
32
|
|
|
31
33
|
private
|
|
32
34
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
else 2000 # or 1800, not possible to tell.
|
|
41
|
-
end
|
|
35
|
+
# Folkeregisterforskriften § 2-2-1
|
|
36
|
+
def century(serial, year)
|
|
37
|
+
return 1900 if serial < 500
|
|
38
|
+
return 2000 if year < 40
|
|
39
|
+
return 1900 if serial >= 900
|
|
40
|
+
return 1800 if serial < 750 && year >= 54
|
|
41
|
+
nil
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
def calculate_checksum(number)
|
|
@@ -32,7 +32,7 @@ module NationalIdentificationNumber
|
|
|
32
32
|
day = $3
|
|
33
33
|
born = Date.new(year.to_i, month.to_i, day.to_i)
|
|
34
34
|
sep = born < Date.today.prev_year(100) ? '+' : '-'
|
|
35
|
-
@number = "#{year[2
|
|
35
|
+
@number = "#{year[2..-1]}#{month}#{day}#{sep}#{$4}"
|
|
36
36
|
rescue Date::Error
|
|
37
37
|
nil
|
|
38
38
|
end
|
|
@@ -61,7 +61,7 @@ describe NationalIdentificationNumber::Norwegian do
|
|
|
61
61
|
it 'recognizes valid numbers' do
|
|
62
62
|
expect(described_class.new('11077941012').age).to eq 42
|
|
63
63
|
expect(described_class.new('01010010000').age).to eq 122
|
|
64
|
-
expect(described_class.new('11077950020').age).to
|
|
64
|
+
expect(described_class.new('11077950020').age).to eq 142
|
|
65
65
|
expect(described_class.new('03032050068').age).to eq 2
|
|
66
66
|
expect(described_class.new('11095231138').age).to eq 69
|
|
67
67
|
expect(described_class.new('21116422341').age).to eq 57
|
|
@@ -85,6 +85,26 @@ describe NationalIdentificationNumber::Norwegian do
|
|
|
85
85
|
end
|
|
86
86
|
end
|
|
87
87
|
|
|
88
|
+
describe '#date' do
|
|
89
|
+
it 'reads the century from the individual number' do
|
|
90
|
+
expect(described_class.new('15010000995').date).to eq Date.new(1900, 1, 15)
|
|
91
|
+
expect(described_class.new('15016549999').date).to eq Date.new(1965, 1, 15)
|
|
92
|
+
expect(described_class.new('15015474960').date).to eq Date.new(1854, 1, 15)
|
|
93
|
+
expect(described_class.new('15019950910').date).to eq Date.new(1899, 1, 15)
|
|
94
|
+
expect(described_class.new('15014099961').date).to eq Date.new(1940, 1, 15)
|
|
95
|
+
expect(described_class.new('15016595052').date).to eq Date.new(1965, 1, 15)
|
|
96
|
+
expect(described_class.new('15019990971').date).to eq Date.new(1999, 1, 15)
|
|
97
|
+
expect(described_class.new('15010099959').date).to eq Date.new(2000, 1, 15)
|
|
98
|
+
expect(described_class.new('15013950951').date).to eq Date.new(2039, 1, 15)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it 'is invalid when the individual number is never issued for that year' do
|
|
102
|
+
expect(described_class.new('15016589869')).not_to be_valid
|
|
103
|
+
expect(described_class.new('15016575965')).not_to be_valid
|
|
104
|
+
expect(described_class.new('15015374869')).not_to be_valid
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
88
108
|
describe '#to_s' do
|
|
89
109
|
it 'returns the number normalized regardless of wether it is valid' do
|
|
90
110
|
expect(described_class.new('311280999J').to_s).to eq '311280999'
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: resident
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.17
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bukowskis
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: rspec
|
|
@@ -38,8 +37,6 @@ dependencies:
|
|
|
38
37
|
- - ">="
|
|
39
38
|
- !ruby/object:Gem::Version
|
|
40
39
|
version: '0'
|
|
41
|
-
description:
|
|
42
|
-
email:
|
|
43
40
|
executables: []
|
|
44
41
|
extensions: []
|
|
45
42
|
extra_rdoc_files: []
|
|
@@ -63,7 +60,6 @@ homepage: http://github.com/bukowskis/national_identification_number/
|
|
|
63
60
|
licenses:
|
|
64
61
|
- MIT-LICENSE
|
|
65
62
|
metadata: {}
|
|
66
|
-
post_install_message:
|
|
67
63
|
rdoc_options: []
|
|
68
64
|
require_paths:
|
|
69
65
|
- lib
|
|
@@ -79,8 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
79
75
|
- !ruby/object:Gem::Version
|
|
80
76
|
version: '0'
|
|
81
77
|
requirements: []
|
|
82
|
-
rubygems_version:
|
|
83
|
-
signing_key:
|
|
78
|
+
rubygems_version: 4.0.3
|
|
84
79
|
specification_version: 4
|
|
85
80
|
summary: Validate National Identification Numbers.
|
|
86
81
|
test_files: []
|