kennitala 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -0
  3. data/Gemfile.lock +1 -1
  4. data/lib/kennitala.rb +17 -4
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d35f02ba753cae3e03263f8fb33fa11bd425855d49dbead29c5661edd2eef1ac
4
- data.tar.gz: aded0d8ea8337bd0a4d7d639b24d36c166f0e2100111cf94f6680de18040f7a8
3
+ metadata.gz: a8792edca881857efe4e1c11478d824647b9ec0ae1a1cfadef0f90186b573774
4
+ data.tar.gz: 2116570f2dc96220c2202d0dee1f73033dd47155c64b3c2ec31775ca632fe7a3
5
5
  SHA512:
6
- metadata.gz: 74f549441ebda6b238140412b8eb4175e0bdb6a6ea6a4e2d3e1b142adfbe70c03c62cee9e0709082535d3beb72fd7e213fccc83f4bf6290dadcda48c7ce34dfb
7
- data.tar.gz: fbadc0f4bcce4f941a23d699be2aaeac1b4afd720e6ad3ae87c151d9caa7183ff835066a8a589e0c4bfcedceb924d2a0f2023cd71f9e104822f813123da089cb
6
+ metadata.gz: 3b111102355338dbbfdf61952067487758ce09aa878109f5bdad82567564a44263c24aef1c02ee15409ca0f8e3ed5f5b179f5000e860bffd66ae5ba922ab0141
7
+ data.tar.gz: 22b07a7a3af1b56d4f9094fb6fd6c356b28ecfb73f88de2dff4d98e671989397aeca3b3292354b0a557b3cf177e6a99ebd87087b04073d8b29f176a023ddb2bc
data/.rubocop.yml CHANGED
@@ -7,6 +7,8 @@ Metrics/BlockLength:
7
7
  - 'spec/*'
8
8
  Metrics/ClassLength:
9
9
  Enabled: false
10
+ Metrics/MethodLength:
11
+ Max: 15
10
12
  Style/OptionalBooleanParameter:
11
13
  Enabled: false
12
14
  Metrics/AbcSize:
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kennitala (0.1.1)
4
+ kennitala (0.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/lib/kennitala.rb CHANGED
@@ -6,7 +6,7 @@ require_relative 'kennitala_string'
6
6
  # The main Kennitala class
7
7
  class Kennitala
8
8
  # The current version of the gem
9
- VERSION = '0.1.1'
9
+ VERSION = '0.1.2'
10
10
 
11
11
  # Initialize a Kennitala object
12
12
  #
@@ -90,9 +90,19 @@ class Kennitala
90
90
  #
91
91
  # @return [Fixnum]
92
92
  def day
93
- date_integer = @value[0, 2].to_i
94
- return @value[0, 2].to_i if date_integer < 32
95
- return @value[0, 2].to_i - 40 if (date_integer > 40) && (date_integer < 71)
93
+ day_from_value = @value[0, 2].to_s[0, 2].to_i
94
+ day_from_value -= 40 if day_from_value > 40
95
+
96
+ # There are examples of a date overlapping the number of days in the
97
+ # given month. Those are considered to be from the last day of that month
98
+ # instad of the specified out-of-bounds day of the month.
99
+ # This is common for the year 1969 as new registrations were being done en
100
+ # masse.
101
+ last_day_of_month = Date.new(year, month, -1).day
102
+
103
+ return last_day_of_month if day_from_value > last_day_of_month
104
+
105
+ day_from_value
96
106
  end
97
107
 
98
108
  # Get a numeric representation of the month of birth or registration
@@ -252,6 +262,9 @@ class Kennitala
252
262
  day = sanitized_kt[0, 2].to_i
253
263
  day -= 40 if day > 40
254
264
  month = sanitized_kt[2, 2].to_i
265
+
266
+ last_day_of_month = Date.new(year, month, -1).day
267
+ day = last_day_of_month if day > last_day_of_month
255
268
  date = Date.new(year, month, day)
256
269
 
257
270
  return sanitized_kt if checks == true && date.instance_of?(Date)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kennitala
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alda Vigdís Skarphéðinsdóttir
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-08 00:00:00.000000000 Z
11
+ date: 2023-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake