resident 0.0.13 → 0.0.15

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
2
  SHA256:
3
- metadata.gz: bf01e9d01d506e8d1679e55d195fbf5b2b68e4f1ea92e071faa067c628ccdeed
4
- data.tar.gz: 05faa5d541a34c27f6bfd7b3285ca1d7e45b0ec6a8368a76bc989f670bea6f88
3
+ metadata.gz: 10570376ab3b4bace53b841cef776196df2ca868f1b58894245f369ed961ee48
4
+ data.tar.gz: b0ee9c563dca36dc0ef8eea25022970487d157fb648cd0a1078ed4263a12b27a
5
5
  SHA512:
6
- metadata.gz: c5c5dae1f39cfc92325e801ccbe0af1823578afb21ace71433853d9bd689988789bf263751837589c35b89ffdf8affd2c5588971753393de21b86b5492c889a6
7
- data.tar.gz: 6796c74e79556f2a291b6e18657551a5300809951c9310fa4dd5f0788f422b84bdd5ddf1b3cad52e9c175f72429a7c317931ae4c9d2bc5ff47b2d3dc408d87ad
6
+ metadata.gz: fc5284eb2da72ef4fdd8cc67eb2d1b220fd948b69c8e1e950a5f8c3bdc4d4d36fd8c79d6697d92dd1460f305ea1bd1fe98bc9b0a47a5ae87ddcc5ccf8b87ba54
7
+ data.tar.gz: 36c549365b79eeaebbfb20cbc01eac1fb70e788e5b284279e17dc35a0cf927d6ab17ad5c6b0c63e2b3a804436fc82c9143f6fa8d066ca86d71685482cb42ace0
@@ -10,14 +10,14 @@ module NationalIdentificationNumber
10
10
  super
11
11
  @number.gsub!(/[^0-9]/, '')
12
12
  if (matches = @number.match(/\A(?<birthday>[0-9]{6})(?<checksum>[0-9]{4})\z/))
13
- birthday, checksum = matches.values_at(:birthday, :checksum)
13
+ birthday, checksum = %w[birthday checksum].map { |group| matches[group] }
14
14
  @number = "#{birthday}-#{checksum}"
15
15
  end
16
16
  end
17
17
 
18
18
  def validate
19
19
  if (matches = @number.match(/\A(?<day>\d{2})(?<month>\d{2})(?<year>\d{2})-(?<serial>\d{3})(?<checksum>\d{1})\z/))
20
- day, month, year, serial, checksum = matches.values_at(:day, :month, :year, :serial, :checksum)
20
+ day, month, year, serial, checksum = %i[day month year serial checksum].map { |group| matches[group] }
21
21
  begin
22
22
  @date = Date.parse("#{full_year(serial, year)}-#{month}-#{day}")
23
23
  @valid = true
@@ -13,7 +13,8 @@ module NationalIdentificationNumber
13
13
 
14
14
  def validate
15
15
  if (matches = @number.match(/\A(?<day>\d{2})(?<month>\d{2})(?<year>\d{2})(?<serial>\d{3})(?<checksum>\d{2})\z/))
16
- day, month, year, serial, checksum = matches.values_at(:day, :month, :year, :serial, :checksum)
16
+ day, month, year, serial, checksum = %i[day month year serial checksum].map { |group| matches[group] }
17
+
17
18
  sans_checksum = "#{day}#{month}#{year}#{serial}"
18
19
 
19
20
  if checksum == calculate_checksum(sans_checksum)
@@ -53,7 +54,7 @@ module NationalIdentificationNumber
53
54
  def weighted_modulo_11(digits_and_weights)
54
55
  result = 11 - (digits_and_weights.map do |terms|
55
56
  terms.reduce(:*)
56
- end.sum % 11)
57
+ end.reduce(:+) % 11)
57
58
  result > 9 ? 0 : result
58
59
  end
59
60
  end
@@ -25,8 +25,22 @@ module NationalIdentificationNumber
25
25
 
26
26
  protected
27
27
 
28
+ def parse_twelve_digits
29
+ return unless @number.match(/\A(\d{4})(\d{2})(\d{2})(\d{4})\Z/)
30
+ year = $1
31
+ month = $2
32
+ day = $3
33
+ born = Date.new(year.to_i, month.to_i, day.to_i)
34
+ sep = born < Date.today.prev_year(100) ? '+' : '-'
35
+ @number = "#{year[2..]}#{month}#{day}#{sep}#{$4}"
36
+ rescue Date::Error
37
+ nil
38
+ end
39
+
28
40
  def repair
29
41
  super
42
+ return if parse_twelve_digits
43
+
30
44
  if @number.match(/\A(\d{0}|\d{2})(\d{6})(\-{0,1})(\d{4})\Z/)
31
45
  @number = "#{$2}-#{$4}"
32
46
  else
@@ -47,7 +61,7 @@ module NationalIdentificationNumber
47
61
  year = $1.to_i
48
62
  month = $2.to_i
49
63
  day = $3.to_i
50
- divider ||= $4 ||'-'
64
+ divider = $4 || '-'
51
65
  serial = $5.to_i
52
66
 
53
67
  today = Date.today
@@ -59,7 +73,6 @@ module NationalIdentificationNumber
59
73
  century = 1800
60
74
  else
61
75
  preliminary_age = age_for_dob(Date.parse("#{1900 + year}-#{month}-#{day}")) rescue 0
62
- #raise preliminary_age.inspect
63
76
  if preliminary_age > 99
64
77
  # It's unlikely that the person is older than 99, so assume a child when no divider was provided.
65
78
  century = 2000
@@ -62,7 +62,7 @@ describe Swedish, '.generate' do
62
62
  end
63
63
 
64
64
  context 'valid numbers' do
65
- it 'is the sanitize dnumber' do
65
+ it 'is the sanitize number' do
66
66
  expect(Swedish.new('19180123-2669').sanitize).to eq '180123-2669'
67
67
  expect(Swedish.new('00180123-2669').sanitize).to eq '180123-2669'
68
68
  expect(Swedish.new('000180123-2669').sanitize).to eq '180123-2669'
@@ -72,6 +72,11 @@ describe Swedish, '.generate' do
72
72
  expect(Swedish.new('450202-6950').sanitize).to eq '450202-6950'
73
73
  expect(Swedish.new('19450202-6950').sanitize).to eq '450202-6950'
74
74
  end
75
+
76
+ it 'adds - or + depending on century for twelve digit formats' do
77
+ expect(Swedish.new('202401275181').sanitize).to eq "240127-5181"
78
+ expect(Swedish.new('192401275181').sanitize).to eq "240127+5181"
79
+ end
75
80
  end
76
81
  end
77
82
 
@@ -125,7 +130,7 @@ describe Swedish, '.generate' do
125
130
  expect( Swedish.new('0501261853').to_s ).to eq '050126-1853'
126
131
  expect( Swedish.new('050126-1853').to_s ).to eq '050126-1853'
127
132
  expect( Swedish.new('0asdfghj501261853').to_s).to eq '050126-1853'
128
- expect( Swedish.new("190501261853").to_s ).to eq '050126-1853'
133
+ expect( Swedish.new("190501261853").to_s ).to eq '050126+1853'
129
134
  expect( Swedish.new("19050126-1853").to_s ).to eq '050126-1853'
130
135
  expect( Swedish.new("19050126-185d3").to_s ).to eq '050126-1853'
131
136
  expect( Swedish.new("19050126-185d3\n").to_s ).to eq '050126-1853'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resident
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bukowskis
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-28 00:00:00.000000000 Z
11
+ date: 2025-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -38,8 +38,8 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description:
42
- email:
41
+ description:
42
+ email:
43
43
  executables: []
44
44
  extensions: []
45
45
  extra_rdoc_files: []
@@ -63,7 +63,7 @@ homepage: http://github.com/bukowskis/national_identification_number/
63
63
  licenses:
64
64
  - MIT-LICENSE
65
65
  metadata: {}
66
- post_install_message:
66
+ post_install_message:
67
67
  rdoc_options: []
68
68
  require_paths:
69
69
  - lib
@@ -79,8 +79,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  - !ruby/object:Gem::Version
80
80
  version: '0'
81
81
  requirements: []
82
- rubygems_version: 3.0.3.1
83
- signing_key:
82
+ rubygems_version: 3.4.10
83
+ signing_key:
84
84
  specification_version: 4
85
85
  summary: Validate National Identification Numbers.
86
86
  test_files: []