iceland 0.1.13 → 2.0.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: e68b56b4b9a0f44a408049af626052ae90a77f9c
4
- data.tar.gz: be1635676c1ba7878caceeddc82285242ba1e9de
2
+ SHA256:
3
+ metadata.gz: ea97211b447cc3be1d2158043687c34c885c4c01c3e83a92985ee368b217f499
4
+ data.tar.gz: ce4867dd56f805db0301dfc9072fb3129d3711a2916b6e94f920181221b7c3a7
5
5
  SHA512:
6
- metadata.gz: f3d41d85cf0dc94ce1d2ed1bebb5cc89f0e065890a8534f814857a348ffbe6d880e94a2c822e66c8c444a9807868d260bafcd5c7bda1e391512033b974f56e2d
7
- data.tar.gz: 56e62ed486867941cfc7c7c8fe795ba8459d62d71bbde4997a285bbe07eb598956d1dd3e8c9cd0c4c191ee66db7b4451173399de8dd978ac33fb45fc08c48aee
6
+ metadata.gz: 3a7ac739d312168b0549b5a8450bb3343bdc945c5c5fa01edfc6e7579520767868b046ffd640834cc3cf5da9ffe9f4880dc48f1bfc798fd2e34236372cbd0f1a
7
+ data.tar.gz: 9a78d200a7787530f766682341d8c187cb458104aeacac8ed498362f9b1adf563f1b24714baa999a4683fe66c2e5817aaaca49b21cd89f1ae4c10724ab319d45
data/.editorconfig ADDED
@@ -0,0 +1,2 @@
1
+ [*.rb]
2
+ indent_size = 2
@@ -0,0 +1,21 @@
1
+ name: Ruby
2
+
3
+ on: ['push']
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ name: Ruby ${{ matrix.ruby }}
9
+ strategy:
10
+ matrix:
11
+ ruby-version: ['3.1', '3.0', '2.7']
12
+
13
+ steps:
14
+ - uses: actions/checkout@v3
15
+ - name: Set up Ruby
16
+ uses: ruby/setup-ruby@v1
17
+ with:
18
+ ruby-version: ${{ matrix.ruby }}
19
+ bundler-cache: true
20
+ - name: Run rubocop
21
+ run: bundle exec rubocop
data/.rubocop.yml CHANGED
@@ -1,4 +1,12 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6.0
3
+ NewCops: enable
4
+ Metrics/BlockLength:
5
+ Exclude:
6
+ - 'spec/*'
7
+ Metrics/ClassLength:
8
+ Enabled: false
9
+ Style/OptionalBooleanParameter:
10
+ Enabled: false
1
11
  Metrics/AbcSize:
2
12
  Max: 20
3
- Metrics/ClassLength:
4
- Max: 150
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.1.2
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in iceland.gemspec
data/README.md CHANGED
@@ -1,10 +1,9 @@
1
- [![Build Status](https://travis-ci.org/stefanvignir/iceland_gem.svg)](https://travis-ci.org/stefanvignir/iceland_gem)
2
- [![Test Coverage](https://codeclimate.com/github/stefanvignir/iceland_gem/badges/coverage.svg)](https://codeclimate.com/github/stefanvignir/iceland_gem/coverage)
3
- [![Code Climate](https://codeclimate.com/github/stefanvignir/iceland_gem/badges/gpa.svg)](https://codeclimate.com/github/stefanvignir/iceland_gem)
4
-
5
1
  # The Iceland Gem
6
2
 
7
- The Iceland Gem handles Icelandic "kennitala" personal/entity identifiers and Icelandic postal codes.
3
+ The Iceland Gem is a metapackage for the `Kennitala` and `Postnumer` gems.
4
+
5
+ It is recommended that you use those gems instead. This gems remains online for
6
+ backwards-compatibility reasons.
8
7
 
9
8
  ## Installation
10
9
 
@@ -22,147 +21,11 @@ Or install it yourself as:
22
21
 
23
22
  $ gem install iceland
24
23
 
25
- ## Usage
26
-
27
- ### Postal Codes
28
-
29
- Icelandic postal codes are 3-digit numeric identifiers, with the first digit indicating a region and the rest identifying a specific locale within the region.
30
-
31
- Names of locales are provided in dative form by default as per Icelandic postal convention, but nomative forms can be returned by setting the `force_nominative` parameter to `true` when using the `Iceland.all_postal_codes` and `Iceland.locale_by_postal_code` methods.
32
-
33
- (Note that we use the term "locale" as per Universal Postal Union convention to name the town, city or other location the postal code is assigned to.)
34
-
35
- #### Examples
36
-
37
- ```ruby
38
- # Get all postal codes, skipping codes assigned to P.O. boxes.
39
- # This is useful when generating forms.
40
- Iceland.all_postal_codes
41
- # => [{:postal_code=>101, :locale=>"Reykjavík"}, {:postal_code=>103, [...]
42
-
43
- # Get the same postal codes in nomative form
44
- Iceland.all_postal_codes false, true
45
- # => [{:postal_code=>101, :locale=>"Reykjavík"}, {:postal_code=>103, [...]
46
-
47
- # Get all postal codes, including P.O. boxes
48
- Iceland.all_postal_codes true
49
- # => [{:postal_code=>101, :locale=>"Reykjavík"}, {:postal_code=>103, [...]
50
-
51
- # Get the name of locale based on its postal code.
52
- # This is useful when you only save the postal code, but not the locale in a database.
53
- Iceland.locale_by_postal_code 311
54
- # => "Borgarnesi (dreifbýli)"
55
-
56
- # Get the name of the locale in nominative form
57
- Iceland.locale_by_postal_code 311, true
58
- # => "Borgarnes (dreifbýli)"
59
- ```
60
-
61
- ### The Kennitala Class
62
-
63
- The Iceland Gem provides a class to handle "kennitala" identifier codes. The class can be used to sanitize the identifiers and read information like the date of birth (or date of registration in the case of companies and organization), age and the type of entity.
64
-
65
- The class does not access external APIs or databases such National Registry or the Company Registry, so names and status (sex/gender, death, bankruptcy, credit rating etc.) cannot be accessed using the class. However, it can be used to sanitize and validate such data before being sent to external APIs, as such services are provided by private companies, which often charge a specific amount for each query.
66
-
67
- #### Uses of kennitala
68
-
69
- Unlike the US Social Security number and equivalents, the kennitala is only used for identification of persons and companies (as well as other registered organizations) — and is often used internally by educational institutions, companies and other organization as a primary identifier for persons (e.g. school, employee, customer and frequent flyer ID). It is not to be used for authentication (i.e. a password) and is not considered a secret per se. While a kennitala can be kept unencrypted in a database, publishing a kennitala or a list of them is generally not considered good practice and might cause liability.
70
-
71
- A kennitala is assigned to every newborn person and foreign nationals residing in Iceland as well as organizations and companies operating there. It is statically assigned and can not be changed.
72
-
73
- Article II, paragraph 10 of the 77/2000 Act on Data Protection (http://www.althingi.is/lagas/nuna/2000077.html) provides the legal framework regarding the use and processing of the kennitala in Iceland:
74
-
75
- > The use of a kennitala is allowed if it has a an objective cause and is necessary to ensure reliable identification of persons. The Data Protection Authority may ban or order the use of kennitala.
24
+ ## Change log
76
25
 
77
- #### Technicalities
26
+ * v2.0.0 - This gem has been changed into a metapackage for the `Kennitala` and `Postnumer` gems.
78
27
 
79
- The kennitala (`DDMMYY-RRCM`) is a 10-digit numeric string consisting on a date (date of birth for persons, date of registration for companies) in the form of `DDMMYY`, three two random digits (`RR`) a check digit (`C`) and a century identifier (`M`). A hyphen or space is often added between the year and random values (Example: `010130-2989`).
80
-
81
- The number 40 is added to the registration day of companies and organizations. Hence, a kennitala for a company registered at January 1 1990 starts with `410190` as opposed to `010190` for a person born that day.
82
-
83
- The century identifier has 3 legal values. `8` for the 19th century, `9` for the 20th century and `0` for the 21st century.
84
-
85
- #### Examples
86
-
87
- ##### Working with Kennitala objects
88
-
89
- ```ruby
90
- # Initialize a Kennitala object.
91
- # The string provided may include spaces, hyphens and alphabetical characters,
92
- # which will then be erased from the resulting string.
93
- k = Kennitala.new(' 010130-2989')
94
- # => #<Kennitala:0x007fe35d041bc0 @value="0101302989">
95
-
96
- # Invalid strings are rejected with an argument error
97
- f = Kennitala.new('010130-2979')
98
- # => ArgumentError: Kennitala is invalid
99
-
100
- # If no kennitala string is specified, a random one will be generated
101
- r = Kennitala.new
102
- # => #<Kennitala:0x007fc589339f18 @value="2009155509">
103
-
104
- # Retrieve the kennitala as a string.
105
- # This is a sanitized string, without any non-numeric characters.
106
- # Pretty useful when storing it in a database.
107
- k.to_s
108
- # => "0101302989"
109
-
110
- # Pretty print the kennitala
111
- # Adds a space between the 6th and the 7th digits for readability
112
- k.pp
113
- # => "010130 2989"
114
-
115
- # You can also pass a string to .pp to use as a spacer
116
- k.pp('–')
117
- # => "010130-2989"
118
-
119
- # You can also pass a cat to the .pp method
120
- k.pp('🐈')
121
- # => "010130🐈2989"
122
-
123
- # Get the entity type (results in 'person' or 'company')
124
- k.entity_type
125
- # => "person"
126
-
127
- # It's also possible to use .company and .person to achieve the same thing
128
- k.company?
129
- # => false
130
-
131
- k.person?
132
- # => true
133
-
134
- # Cast the kennitala to a Date object
135
- k.to_date
136
- # => #<Date: 1930-01-01 ((2425978j,0s,0n),+0s,2299161j)>
137
-
138
- # Get the current age of the entity. Useful for age restrictions.
139
- k.age
140
- # => 86
141
- ```
142
-
143
- ##### Casting strings
144
-
145
- ```ruby
146
- # Casting a string to a Kennitala object
147
- '010130 2989'.to_kt
148
- # => #<Kennitala:0x007fc5893286a0 @value="0101302989">
149
-
150
- # Get the current age based on a String
151
- '0101302989'.to_kt.age
152
- # => 86
153
- ```
154
-
155
- ## Todo
156
-
157
- * Administrative Divisions
158
- * Bank accounts
159
- * Car plate numbers
160
-
161
- ## About the data
162
-
163
- The Postal code data is based on data files provided by Iceland Post. The files are available at http://www.postur.is/um-postinn/posthus/postnumer/gagnaskrar/ and are provided for free for any use by individuals and organizations.
164
-
165
- Strings are expected to be UTF-8.
28
+ ## Usage
166
29
 
167
30
  ## Development
168
31
 
data/bin/console CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler/setup'
4
5
  require 'iceland'
data/iceland.gemspec CHANGED
@@ -1,21 +1,20 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'iceland/version'
5
+ require 'iceland'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
8
  spec.name = 'iceland'
8
9
  spec.version = Iceland::VERSION
9
- spec.authors = ['Stefan Vignir']
10
- spec.email = ['stefanvignir@stefanvignir.is']
10
+ spec.authors = ['Alda Vigdís']
11
+ spec.email = ['aldavigdis@aldavigdis.is']
12
+
13
+ spec.summary = 'A meta package of the Postnumer and Kennitala gems.'
11
14
 
12
- spec.summary = 'Handles the Icelandic "kennitala" identification '\
13
- 'scheme and postal codes'
14
- spec.description = 'Adds the Kennitala class. Figures out dates and ages, '\
15
- 'and sanitizes "kennitala" objects and looks up '\
16
- 'Icelandic postal codes.'
17
15
  spec.homepage = 'https://github.com/stefanvignir/iceland_gem'
18
16
  spec.license = 'MIT'
17
+ spec.required_ruby_version = '>= 2.6.0'
19
18
 
20
19
  spec.files = `git ls-files -z`
21
20
  .split("\x0")
@@ -24,10 +23,11 @@ Gem::Specification.new do |spec|
24
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
24
  spec.require_paths = ['lib']
26
25
 
27
- spec.add_development_dependency 'bundler', '~> 1.11'
28
- spec.add_development_dependency 'rake', '~> 10.0'
29
- spec.add_development_dependency 'rspec', '~> 3.0'
30
- spec.add_development_dependency 'rubocop', '~> 0.40.0'
31
- spec.add_development_dependency 'overcommit', '~> 0.33.0'
32
- spec.add_development_dependency 'codeclimate-test-reporter', '~> 0.5.0'
26
+ spec.add_development_dependency 'bundler', '~> 2.3.7'
27
+ spec.add_development_dependency 'rake', '~> 13.0'
28
+ spec.add_development_dependency 'rubocop', '~> 1.44'
29
+
30
+ spec.add_runtime_dependency 'kennitala', '~> 0.1'
31
+ spec.add_runtime_dependency 'postnumer', '~> 0.2'
32
+ spec.metadata['rubygems_mfa_required'] = 'true'
33
33
  end
data/lib/iceland.rb CHANGED
@@ -1,7 +1,5 @@
1
- require 'date'
2
- require 'yaml'
1
+ # frozen_string_literal: true
3
2
 
4
- require 'iceland/version'
5
- require 'iceland/postal_codes'
6
- require 'iceland/kennitala'
7
- require 'iceland/kennitala_string'
3
+ class Iceland
4
+ VERSION = '2.0.0'
5
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iceland
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - Stefan Vignir
8
- autorequire:
7
+ - Alda Vigdís
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-17 00:00:00.000000000 Z
11
+ date: 2023-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,116 +16,98 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.11'
19
+ version: 2.3.7
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.11'
26
+ version: 2.3.7
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '13.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
41
- - !ruby/object:Gem::Dependency
42
- name: rspec
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '3.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '3.0'
40
+ version: '13.0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: rubocop
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
45
  - - "~>"
60
46
  - !ruby/object:Gem::Version
61
- version: 0.40.0
47
+ version: '1.44'
62
48
  type: :development
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
52
  - - "~>"
67
53
  - !ruby/object:Gem::Version
68
- version: 0.40.0
54
+ version: '1.44'
69
55
  - !ruby/object:Gem::Dependency
70
- name: overcommit
56
+ name: kennitala
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
59
  - - "~>"
74
60
  - !ruby/object:Gem::Version
75
- version: 0.33.0
76
- type: :development
61
+ version: '0.1'
62
+ type: :runtime
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
66
  - - "~>"
81
67
  - !ruby/object:Gem::Version
82
- version: 0.33.0
68
+ version: '0.1'
83
69
  - !ruby/object:Gem::Dependency
84
- name: codeclimate-test-reporter
70
+ name: postnumer
85
71
  requirement: !ruby/object:Gem::Requirement
86
72
  requirements:
87
73
  - - "~>"
88
74
  - !ruby/object:Gem::Version
89
- version: 0.5.0
90
- type: :development
75
+ version: '0.2'
76
+ type: :runtime
91
77
  prerelease: false
92
78
  version_requirements: !ruby/object:Gem::Requirement
93
79
  requirements:
94
80
  - - "~>"
95
81
  - !ruby/object:Gem::Version
96
- version: 0.5.0
97
- description: Adds the Kennitala class. Figures out dates and ages, and sanitizes "kennitala"
98
- objects and looks up Icelandic postal codes.
82
+ version: '0.2'
83
+ description:
99
84
  email:
100
- - stefanvignir@stefanvignir.is
85
+ - aldavigdis@aldavigdis.is
101
86
  executables: []
102
87
  extensions: []
103
88
  extra_rdoc_files: []
104
89
  files:
105
- - ".codeclimate.yml"
90
+ - ".editorconfig"
91
+ - ".github/workflows/main.yml"
106
92
  - ".gitignore"
107
93
  - ".overcommit.yml"
108
94
  - ".rspec"
109
95
  - ".rubocop.yml"
96
+ - ".ruby-version"
110
97
  - ".travis.yml"
111
98
  - Gemfile
112
99
  - LICENSE.txt
113
100
  - README.md
114
- - Rakefile
115
101
  - bin/console
116
102
  - bin/setup
117
103
  - iceland.gemspec
118
104
  - lib/iceland.rb
119
- - lib/iceland/kennitala.rb
120
- - lib/iceland/kennitala_string.rb
121
- - lib/iceland/postal_codes.rb
122
- - lib/iceland/version.rb
123
- - lib/postcodes.yml
124
105
  homepage: https://github.com/stefanvignir/iceland_gem
125
106
  licenses:
126
107
  - MIT
127
- metadata: {}
128
- post_install_message:
108
+ metadata:
109
+ rubygems_mfa_required: 'true'
110
+ post_install_message:
129
111
  rdoc_options: []
130
112
  require_paths:
131
113
  - lib
@@ -133,17 +115,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
133
115
  requirements:
134
116
  - - ">="
135
117
  - !ruby/object:Gem::Version
136
- version: '0'
118
+ version: 2.6.0
137
119
  required_rubygems_version: !ruby/object:Gem::Requirement
138
120
  requirements:
139
121
  - - ">="
140
122
  - !ruby/object:Gem::Version
141
123
  version: '0'
142
124
  requirements: []
143
- rubyforge_project:
144
- rubygems_version: 2.4.5.1
145
- signing_key:
125
+ rubygems_version: 3.3.7
126
+ signing_key:
146
127
  specification_version: 4
147
- summary: Handles the Icelandic "kennitala" identification scheme and postal codes
128
+ summary: A meta package of the Postnumer and Kennitala gems.
148
129
  test_files: []
149
- has_rdoc:
data/.codeclimate.yml DELETED
@@ -1,16 +0,0 @@
1
- ---
2
- engines:
3
- duplication:
4
- enabled: true
5
- config:
6
- languages:
7
- - ruby
8
- fixme:
9
- enabled: true
10
- rubocop:
11
- enabled: true
12
- ratings:
13
- paths:
14
- - "**.rb"
15
- exclude_paths:
16
- - spec/
data/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task default: :spec
@@ -1,293 +0,0 @@
1
- # The Kennitala Class
2
- class Kennitala
3
- # Initialize a Kennitala object
4
- #
5
- # @note The string provided may include spaces, hyphens and alphabetical
6
- # characters, which will then be erased from the resulting string.
7
- #
8
- # @param [String, Boolean] kt_string Either Kennitala String or Boolean false.
9
- # @param [Boolean] is_company Wether the randomly generated kennitala is
10
- # for a company
11
- # @return [Kennitala] description of returned object
12
- #
13
- # @example Initialize a Kennitala object based on an unsanitized String
14
- # Kennitala.new(' 010130-2989')
15
- # => #<Kennitala:0x007fe35d041bc0 @value="0101302989">
16
- #
17
- # @example Invalid strings are rejected with an argument error
18
- # Kennitala.new('010130-2979')
19
- # => ArgumentError: Kennitala is invalid
20
- #
21
- # @example If no kennitala string is specified, a random one will be generated
22
- # Kennitala.new
23
- # => #<Kennitala:0x007fc589339f18 @value="2009155509">
24
- def initialize(kt_string = false, is_company = false)
25
- kt_string = fake_kt_string(is_company) if kt_string == false
26
- unless kt_string.class == String
27
- raise ArgumentError, 'Kennitala needs to be provided as a String or '\
28
- 'Boolean (false)'
29
- end
30
- sanitised_kt = sanitize(kt_string)
31
- raise ArgumentError, 'Kennitala is invalid' if sanitised_kt.nil?
32
- @value = sanitised_kt
33
- end
34
-
35
- # Get the type of entity - If it is a person or an organization
36
- #
37
- # @return [String] Either 'person' or 'company'
38
- #
39
- # @example Get the entity type (results in 'person' or 'company')
40
- # k = Kennitala.new('0101302989')
41
- # => #<Kennitala:0x007fe35d041bc0 @value="0101302989">
42
- # k.entity_type
43
- # => "person"
44
- def entity_type
45
- date_integer = @value[0, 2].to_i
46
- return 'person' if date_integer < 32
47
- return 'company' if (date_integer > 40) && (date_integer < 72)
48
- end
49
-
50
- # Check if the entity is a company
51
- #
52
- # @return [Boolean]
53
- def company?
54
- date_integer = @value[0, 2].to_i
55
- return true if (date_integer > 40) && (date_integer < 72)
56
- false
57
- end
58
-
59
- # Check if the entity is a person
60
- #
61
- # @return [Boolean]
62
- def person?
63
- date_integer = @value[0, 2].to_i
64
- return true if date_integer < 32
65
- false
66
- end
67
-
68
- # Get the year of birth or registration
69
- #
70
- # @return [Fixnum]
71
- def year
72
- century = (10 + @value[9].to_i) * 100
73
- year = @value[4, 2].to_i
74
- return century + year if (1800..1900).cover?(century)
75
- return 2000 + year if century == 1000
76
- end
77
-
78
- # Get the day of the month of birth or registration
79
- #
80
- # @return [Fixnum]
81
- def day
82
- date_integer = @value[0, 2].to_i
83
- return @value[0, 2].to_i if date_integer < 32
84
- return @value[0, 2].to_i - 40 if (date_integer > 40) && (date_integer < 71)
85
- end
86
-
87
- # Get a numeric representation of the month of birth or registration
88
- #
89
- # @return [Fixnum]
90
- def month
91
- @value[2, 2].to_i
92
- end
93
-
94
- # Get the age of entity in years. Useful when dealing with age restrictions.
95
- #
96
- # @return [Fixnum]
97
- #
98
- # @example Get the current age of the entity
99
- # k = Kennitala.new('0101302989')
100
- # => #<Kennitala:0x007fe35d041bc0 @value="0101302989">
101
- # k.age
102
- # => 86
103
- def age
104
- year_diff = Date.today.year - to_date.year
105
- month_diff = Date.today.month - to_date.month
106
- day_diff = Date.today.month - to_date.month
107
-
108
- return year_diff -= 1 if month_diff < 0 || (month_diff == 0 && day_diff < 0)
109
- year_diff
110
- end
111
-
112
- # Cast the kennitala to a Date object
113
- #
114
- # @return [Date]
115
- #
116
- # @example Cast the kennitala to a Date object
117
- # k = Kennitala.new('0101302989')
118
- # => #<Kennitala:0x007fe35d041bc0 @value="0101302989">
119
- # k.to_date
120
- # => #<Date: 1930-01-01 ((2425978j,0s,0n),+0s,2299161j)>
121
- def to_date
122
- Date.new(year, month, day)
123
- end
124
-
125
- # Cast the kennitala to a String object
126
- #
127
- # @return [String]
128
- def to_s
129
- @value.to_s
130
- end
131
-
132
- # Pretty print a kennitala
133
- #
134
- # Adds a space between the 6th and the 7th digits for readability.
135
- #
136
- # @param [String] spacer A single space by default
137
- # @return [String]
138
- #
139
- # @example Pretty print a Kennitala it its default form
140
- # k = Kennitala.new('0101302989')
141
- # => #<Kennitala:0x007fc589339f18 @value="2009155509">
142
- # k.pp
143
- # => "010130 2989"
144
- #
145
- # @example Use a hyphen as a spacer instead of the default single space
146
- # k = Kennitala.new('0101302989')
147
- # => #<Kennitala:0x007fc589339f18 @value="2009155509">
148
- # k.pp('-')
149
- # => "010130-2989"
150
- def pp(spacer = ' ')
151
- raise ArgumentError 'Spacer must be a string' unless spacer.class == String
152
- @value[0, 6] + spacer + @value[6, 9]
153
- end
154
-
155
- private
156
-
157
- # Generate fake a birth number and check digit based on the first 6 digits
158
- #
159
- # @param [String] The first six digits is a kennitala
160
- # @return [Hash, nil]
161
- def fake_randoms(date_hash)
162
- first_six = date_hash[:day] + date_hash[:month] + date_hash[:year]
163
- loop do
164
- birth_number = Random.rand(1..99).to_s.rjust(2, '0')
165
- first_eight = "#{first_six}#{birth_number}"
166
- check_digit = calculate_check_digit(first_eight)
167
- if check_checksum(first_eight)
168
- return { check_digit: check_digit, birth_number: birth_number }
169
- end
170
- end
171
- end
172
-
173
- # Generate a fake year and century Hash
174
- #
175
- # @return [Hash]
176
- def fake_year
177
- century = [9, 9, 9, 8, 0, 0].sample
178
- current_year = Date.today.strftime('%y').to_i
179
- if century == 0
180
- return { year: Random.rand(0..current_year), century: century }
181
- else
182
- return { year: Random.rand(0..99), century: century }
183
- end
184
- end
185
-
186
- # Generate a fake hash that includes randomly generated date elements
187
- #
188
- # @todo Take leap years into account and thus allow for 29 February
189
- #
190
- # @param [Boolean] is_company true if the day string is for a company
191
- # @return [Hash]
192
- def fake_date_hash(is_company = false)
193
- year_hash = fake_year
194
-
195
- month_days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
196
- month = Random.rand(1..12)
197
-
198
- day = Random.rand(1..month_days[month - 1])
199
- day = (day.to_i + 40).to_s.rjust(2, '0') if is_company == true
200
-
201
- { century: year_hash[:century].to_s,
202
- year: year_hash[:year].to_s.rjust(2, '0'),
203
- month: month.to_s.rjust(2, '0'), day: day.to_s.rjust(2, '0') }
204
- end
205
-
206
- # Generate a fake, random kennitala string
207
- #
208
- # @param [Boolean] is_company If the kennitala is for a company, not a person
209
- # @return [String] A 10-digit string representing a kennitala
210
- def fake_kt_string(is_company = false)
211
- date_hash = fake_date_hash(is_company)
212
- randoms_hash = fake_randoms(date_hash)
213
-
214
- first_six = date_hash[:day] + date_hash[:month] + date_hash[:year]
215
- randoms = randoms_hash[:birth_number].to_s + randoms_hash[:check_digit].to_s
216
-
217
- first_six + randoms + date_hash[:century]
218
- end
219
-
220
- # Get year from a kennitala string
221
- #
222
- # @param [String] kt_string Sanitized kennitala string
223
- # @return [Fixnum] description of returned object
224
- def get_year_from_string(kt_string)
225
- century_code = kt_string[9, 1].to_i
226
- case century_code
227
- when 0
228
- return "20#{kt_string[4, 2]}".to_i
229
- when 8..9
230
- return "1#{century_code}#{kt_string[4, 2]}".to_i
231
- end
232
- end
233
-
234
- # Sanitize the kennitala
235
- #
236
- # @param [String] kt_string Unsanitised string representing a kennitala
237
- # @return [String, nil] Sanitized kennitala, nil if invalid
238
- def sanitize(kt_string)
239
- sanitized_kt = kt_string.gsub(/[^0-9]/, '')
240
- checks = check_checksum(sanitized_kt)
241
-
242
- year = get_year_from_string(sanitized_kt)
243
- day = sanitized_kt[0, 2].to_i
244
- day -= 40 if day > 40
245
- month = sanitized_kt[2, 2].to_i
246
- date = Date.new(year, month, day)
247
-
248
- return sanitized_kt if checks == true && date.class == Date
249
-
250
- rescue ArgumentError, 'invalid date'
251
- nil
252
- end
253
-
254
- # Calculate the checksum
255
- #
256
- # @param [String] kt_string Sanitized kennitala
257
- # @return [Fixnum] The checksum
258
- def checksum(kt_string)
259
- checksum = 0
260
- multipliers = [3, 2, 7, 6, 5, 4, 3, 2]
261
- multipliers.each_with_index do |multiplier, index|
262
- checksum += multiplier * kt_string[index].to_i
263
- end
264
- checksum
265
- end
266
-
267
- # Calculate the check digit for a kennitala
268
- #
269
- # @param [String] kt_string Sanitized kennitala
270
- # @return [Fixnum]
271
- def calculate_check_digit(kt_string)
272
- remainder = checksum(kt_string).modulo(11)
273
-
274
- # A kennitala with a remainder of 10 is always considered to be invalid
275
- return nil if remainder == 10
276
-
277
- # The check digit should be 11 minus the remainder,
278
- # unless the remainder is 0, then the theck digit becomes 0.
279
- return 0 if remainder == 0
280
- 11 - remainder
281
- end
282
-
283
- # Check validity of the check digit
284
- #
285
- # @param [String] kt_string Sanitized kennitala
286
- # @return [Boolean, nil] true on success, false if the check digit is invalid
287
- def check_checksum(kt_string)
288
- expected_check_digit = calculate_check_digit(kt_string)
289
- actual_check_digit = kt_string[8].to_i
290
- return true if expected_check_digit == actual_check_digit
291
- false
292
- end
293
- end
@@ -1,9 +0,0 @@
1
- # Monkey patch for the String class
2
- class String
3
- # Converts a String to a Kennitala object
4
- #
5
- # @return [Kennitala]
6
- def to_kt
7
- Kennitala.new(self)
8
- end
9
- end
@@ -1,42 +0,0 @@
1
- # Postal Codes
2
- module Iceland
3
- # The postal code data as a Hash object
4
- POSTAL_CODES = YAML.load_file(File.expand_path('../../postcodes.yml',
5
- __FILE__))
6
-
7
- # Get an array of hashes with postal_code and locale attributes
8
- #
9
- # @param [Boolean] include_po_boxes Include postal codes for P.O. boxes
10
- # @param [Boolean] force_nominative Use the nomative version of locale name
11
- # @return [Array]
12
- def all_postal_codes(include_po_boxes = false, force_nominative = false)
13
- pairs = []
14
- POSTAL_CODES.each do |postal_code, p|
15
- # Skip P.O. boxes
16
- next if (include_po_boxes == false) && (p['is_po_box'] == true)
17
- # Retun the dative form of the locale by default
18
- pairs << if p['dative'].nil? || force_nominative == true
19
- { postal_code: postal_code, locale: p['locale'] }
20
- else
21
- { postal_code: postal_code, locale: p['dative'] }
22
- end
23
- end
24
- pairs
25
- end
26
-
27
- # Find the name of locale (city/town/village) by postal code
28
- #
29
- # @param [Integer, String] postal_code The postal code
30
- # @param [Boolean] force_nominative Display locale name in nomative form
31
- # @return [String]
32
- def locale_by_postal_code(postal_code, force_nominative = false)
33
- postal_code = postal_code.to_i
34
- postal_code_hash = POSTAL_CODES[postal_code]
35
- unless postal_code_hash.nil?
36
- if postal_code_hash['dative'].nil? || force_nominative == true
37
- return postal_code_hash['locale']
38
- end
39
- postal_code_hash['dative']
40
- end
41
- end
42
- end
@@ -1,3 +0,0 @@
1
- module Iceland
2
- VERSION = '0.1.13'.freeze
3
- end
data/lib/postcodes.yml DELETED
@@ -1,441 +0,0 @@
1
- 101:
2
- locale: 'Reykjavík'
3
- 103:
4
- locale: 'Reykjavík'
5
- 104:
6
- locale: 'Reykjavík'
7
- 105:
8
- locale: 'Reykjavík'
9
- 107:
10
- locale: 'Reykjavík'
11
- 108:
12
- locale: 'Reykjavík'
13
- 109:
14
- locale: 'Reykjavík'
15
- 110:
16
- locale: 'Reykjavík'
17
- 111:
18
- locale: 'Reykjavík'
19
- 112:
20
- locale: 'Reykjavík'
21
- 113:
22
- locale: 'Reykjavík'
23
- 116:
24
- locale: 'Reykjavík'
25
- 121:
26
- locale: 'Reykjavík'
27
- is_po_box: true
28
- 123:
29
- locale: 'Reykjavík'
30
- is_po_box: true
31
- 124:
32
- locale: 'Reykjavík'
33
- is_po_box: true
34
- 125:
35
- locale: 'Reykjavík'
36
- is_po_box: true
37
- 127:
38
- locale: 'Reykjavík'
39
- is_po_box: true
40
- 128:
41
- locale: 'Reykjavík'
42
- is_po_box: true
43
- 129:
44
- locale: 'Reykjavík'
45
- is_po_box: true
46
- 130:
47
- locale: 'Reykjavík'
48
- is_po_box: true
49
- 132:
50
- locale: 'Reykjavík'
51
- is_po_box: true
52
- 150:
53
- locale: 'Reykjavík'
54
- corporate_services: true
55
- 155:
56
- locale: 'Reykjavík'
57
- corporate_services: true
58
- 170:
59
- locale: 'Seltjarnarnes'
60
- dative: 'Seltjarnarnesi'
61
- 190:
62
- locale: 'Vogar'
63
- dative: 'Vogum'
64
- 200:
65
- locale: 'Kópavogur'
66
- dative: 'Kópavogi'
67
- 201:
68
- locale: 'Kópavogur'
69
- dative: 'Kópavogi'
70
- 202:
71
- locale: 'Kópavogur'
72
- dative: 'Kópavogi'
73
- 203:
74
- locale: 'Kópavogur'
75
- dative: 'Kópavogi'
76
- 210:
77
- locale: 'Garðabær'
78
- dative: 'Garðabæ'
79
- 212:
80
- locale: 'Garðabær'
81
- dative: 'Garðabæ'
82
- is_po_box: true
83
- 220:
84
- locale: 'Hafnarfjörður'
85
- dative: 'Hafnarfirði'
86
- 221:
87
- locale: 'Hafnarfjörður'
88
- dative: 'Hafnarfirði'
89
- 222:
90
- locale: 'Hafnarfjörður'
91
- dative: 'Hafnarfirði'
92
- is_po_box: true
93
- 225:
94
- locale: 'Álftanes'
95
- daive: 'Álftanesi'
96
- 230:
97
- locale: 'Reykjanesbær'
98
- dative: 'Reykjanesbæ'
99
- 232:
100
- locale: 'Reykjanesbær'
101
- dative: 'Reykjanesbæ'
102
- is_po_box: true
103
- 233:
104
- locale: 'Reykjanesbær'
105
- dative: 'Reykjanesbæ'
106
- 235:
107
- locale: 'Reykjanesbær'
108
- dative: 'Reykjanesbæ'
109
- 240:
110
- locale: 'Grindavík'
111
- 245:
112
- locale: 'Sandgerði'
113
- 250:
114
- locale: 'Garður'
115
- dative: 'Garði'
116
- 260:
117
- locale: 'Reykjanesbær'
118
- dative: 'Reykjanesbæ'
119
- 270:
120
- locale: 'Mosfellsbær'
121
- dative: 'Mosfellsbæ'
122
- 271:
123
- locale: 'Mosfellsbær'
124
- dative: 'Mosfellsbæ'
125
- 276:
126
- locale: 'Mosfellsbær'
127
- dative: 'Mosfellsbæ'
128
- 300:
129
- locale: 'Akranes'
130
- dative: 'Akranesi'
131
- 301:
132
- locale: 'Akranes (dreifbýli)'
133
- dative: 'Akranesi (dreifbýli)'
134
- is_rural: true
135
- 302:
136
- locale: 'Akranes'
137
- locale: 'Akranesi'
138
- is_po_box: true
139
- 310:
140
- locale: 'Borgarnes'
141
- dative: 'Borgarnesi'
142
- 311:
143
- locale: 'Borgarnes (dreifbýli)'
144
- dative: 'Borgarnesi (dreifbýli)'
145
- is_rural: true
146
- 320:
147
- locale: 'Reykholt í Borgarfirði'
148
- dative: 'Reykholti í Borgarfirði'
149
- is_rural: true
150
- 340:
151
- locale: 'Stykkishólmur'
152
- dative: 'Stykkishólmi'
153
- 345:
154
- locale: 'Flatey á Breiðafirði'
155
- 350:
156
- locale: 'Grundarfjörður'
157
- dative: 'Grundarfirði'
158
- 355:
159
- locale: 'Ólafsvík'
160
- 356:
161
- locale: 'Snæfellsbær'
162
- dative: 'Snæfellsbæ'
163
- is_rural: true
164
- 360:
165
- locale: 'Hellissandur'
166
- dative: 'Hellissandi'
167
- 370:
168
- locale: 'Búðardalur'
169
- dative: 'Búðardal'
170
- 371:
171
- locale: 'Búðardalur (dreifbýli)'
172
- dative: 'Búðardal (dreifbýli)'
173
- is_rural: true
174
- 380:
175
- locale: 'Reykhólahreppur'
176
- dative: 'Reykhólahreppi'
177
- is_rural: true
178
- 400:
179
- locale: 'Ísafjörður'
180
- dative: 'Ísafirði'
181
- 401:
182
- locale: 'Ísafjörður (dreifbýli)'
183
- dative: 'Ísafirði (dreifbýli)'
184
- is_rural: true
185
- 410:
186
- locale: 'Hnífsdalur'
187
- dative: 'Hnífsdal'
188
- is_rural: true
189
- 415:
190
- locale: 'Bolungarvík'
191
- 420:
192
- locale: 'Súðavík'
193
- 425:
194
- locale: 'Flateyri'
195
- 430:
196
- locale: 'Suðureyri'
197
- 450:
198
- locale: 'Patreksfjörður'
199
- dative: 'Patreksfirði'
200
- 451:
201
- locale: 'Patreksfjörður (dreifbýli)'
202
- dative: 'Patreksfirði (dreifbýli)'
203
- is_rural: true
204
- 460:
205
- locale: 'Tálknafjörður'
206
- dative: 'Tálknafirði'
207
- 465:
208
- locale: 'Bíldudalur'
209
- dative: 'Bíldudal'
210
- 470:
211
- locale: 'Þingeyri'
212
- 471:
213
- locale: 'Þingeyri (dreifbýli)'
214
- is_rural: true
215
- 500:
216
- locale: 'Staður'
217
- dative: 'Stað'
218
- is_rural: true
219
- 510:
220
- locale: 'Hólmavík'
221
- 512:
222
- locale: 'Hólmavík (dreifbýli)'
223
- is_rural: true
224
- 520:
225
- locale: 'Drangsnes'
226
- dative: 'Drangsnesi'
227
- 524:
228
- locale: 'Árneshreppur'
229
- dative: 'Árneshreppi'
230
- is_rural: true
231
- 530:
232
- locale: 'Hvammstangi'
233
- dative: 'Hvammstanga'
234
- 531:
235
- locale: 'Hvammstangi (dreifbýli)'
236
- dative: 'Hvammstanga (dreifbýli)'
237
- is_rural: true
238
- 540:
239
- locale: 'Blönduós'
240
- dative: 'Blönduósi'
241
- 541:
242
- locale: 'Blönduós (dreifbýli)'
243
- dative: 'Blönduósi (dreifbýli)'
244
- is_rural: true
245
- 545:
246
- locale: 'Skagaströnd'
247
- 550:
248
- locale: 'Sauðárkrókur'
249
- dative: 'Sauðárkróki'
250
- 551:
251
- locale: 'Sauðárkrókur (dreifbýli)'
252
- dative: 'Sauðárkróki (dreifbýli)'
253
- is_rural: true
254
- 560:
255
- locale: 'Varmahlíð'
256
- 565:
257
- locale: 'Hofsós'
258
- dative: 'Hofsósi'
259
- is_rural: true
260
- 566:
261
- locale: 'Hofsós (dreifbýli)'
262
- dative: 'Hofsósi (dreifbýli)'
263
- is_rural: true
264
- 570:
265
- locale: 'Fljót'
266
- dative: 'Fljótum'
267
- is_rural: true
268
- 580:
269
- locale: 'Siglufjörður'
270
- dative: 'Siglufirði'
271
- 600:
272
- locale: 'Akureyri'
273
- 601:
274
- locale: 'Akureyri (dreifbýli)'
275
- is_rural: true
276
- 602:
277
- locale: 'Akureyri'
278
- is_po_box: true
279
- 603:
280
- locale: 'Akureyri'
281
- 610:
282
- locale: 'Grenivík'
283
- 611:
284
- locale: 'Grímsey'
285
- 620:
286
- locale: 'Dalvík'
287
- 621:
288
- locale: 'Dalvík (dreifbýli)'
289
- is_rural: true
290
- 625:
291
- locale: 'Ólafsfjörður'
292
- dative: 'Ólafsfirði'
293
- 630:
294
- locale: 'Hrísey'
295
- 640:
296
- locale: 'Húsavík'
297
- 641:
298
- locale: 'Húsavík (dreifbýli)'
299
- is_rural: true
300
- 645:
301
- locale: 'Fosshóll'
302
- dative: 'Fosshóli'
303
- is_rural: true
304
- 650:
305
- locale: 'Laugar'
306
- dative: 'Laugum'
307
- 660:
308
- locale: 'Mývatn'
309
- dative: 'Mývatni'
310
- 670:
311
- locale: 'Kópasker'
312
- dative: 'Kópaskeri'
313
- 671:
314
- locale: 'Kópasker (dreifbýli)'
315
- dative: 'Kópaskeri (dreifbýli)'
316
- is_rural: true
317
- 675:
318
- locale: 'Raufarhöfn'
319
- 680:
320
- locale: 'Þórshöfn'
321
- 681:
322
- locale: 'Þórshöfn (dreifbýli)'
323
- is_rural: true
324
- 685:
325
- locale: 'Bakkafjörður'
326
- dative: 'Bakkafirði'
327
- is_rural: true
328
- 690:
329
- locale: 'Vopnafjörður'
330
- dative: 'Vopnafirði'
331
- 700:
332
- locale: 'Egilsstaðir'
333
- dative: 'Egilsstöðum'
334
- 701:
335
- locale: 'Egilsstaðir (dreifbýli)'
336
- dative: 'Egilsstöðum (dreifbýli)'
337
- is_rural: true
338
- 710:
339
- locale: 'Seyðisfjörður'
340
- dative: 'Seyðisfirði'
341
- 715:
342
- locale: 'Mjóifjörður'
343
- dative: 'Mjóafirði'
344
- is_rural: true
345
- 720:
346
- locale: 'Borgarfjörður (eystri)'
347
- dative: 'Borgarfirði (eystri)'
348
- is_rural: true
349
- 730:
350
- locale: 'Reyðarfjörður'
351
- dative: 'Reyðarfirði'
352
- 735:
353
- locale: 'Eskifjörður'
354
- dative: 'Eskifirði'
355
- 740:
356
- locale: 'Neskaupstaður'
357
- dative: 'Neskaupsstað'
358
- 750:
359
- locale: 'Fáskrúðsfjörður'
360
- dative: 'Fáskrúðsfirði'
361
- 755:
362
- locale: 'Stöðvarfjörður'
363
- dative: 'Stöðvarfirði'
364
- 760:
365
- locale: 'Breiðdalsvík'
366
- 765:
367
- locale: 'Djúpivogur'
368
- dative: 'Djúpavogi'
369
- 780:
370
- locale: 'Höfn í Hornafirði'
371
- 781:
372
- locale: 'Höfn í Hornafirði (dreifbýli)'
373
- is_rural: true
374
- 785:
375
- locale: 'Öræfi'
376
- dative: 'Öræfum'
377
- is_rural: true
378
- 800:
379
- locale: 'Selfoss'
380
- dative: 'Selfossi'
381
- 801:
382
- locale: 'Selfoss (dreifbýli)'
383
- dative: 'Selfossi (dreifbýli)'
384
- is_rural: true
385
- 802:
386
- locale: 'Selfoss'
387
- dative: 'Selfossi'
388
- is_po_box: true
389
- 810:
390
- locale: 'Hveragerði'
391
- 815:
392
- locale: 'Þorlákshöfn'
393
- 816:
394
- locale: 'Ölfus (dreifbýli)'
395
- dative: 'Ölfusi (dreifbýli)'
396
- is_rural: true
397
- 820:
398
- locale: 'Eyrarbakki'
399
- dative: 'Eyrarbakka'
400
- is_rural: true
401
- 825:
402
- locale: 'Stokkseyri'
403
- is_rural: true
404
- 840:
405
- locale: 'Laugarvatn'
406
- dative: 'Laugarvatni'
407
- is_rural: true
408
- 845:
409
- locale: 'Flúðir'
410
- dative: 'Flúðum'
411
- is_rural: true
412
- 850:
413
- locale: 'Hella'
414
- dative: 'Hellu'
415
- 851:
416
- locale: 'Hella (dreifbýli)'
417
- dative: 'Hellu (dreifbýli)'
418
- 860:
419
- locale: 'Hvolsvöllur'
420
- dative: 'Hvolsvelli'
421
- 861:
422
- locale: 'Hvolsvöllur (dreifbýli)'
423
- dative: 'Hvolsvelli (dreifbýli)'
424
- 870:
425
- locale: 'Vík'
426
- is_rural: true
427
- 871:
428
- locale: 'Vík (dreifbýli)'
429
- is_rural: true
430
- 880:
431
- locale: 'Kirkjubæjarklaustur'
432
- dative: 'Kirkjubæjarklaustri'
433
- is_rural: true
434
- 900:
435
- locale: 'Vestmannaeyjar'
436
- dative: 'Vestmannaeyjum'
437
- is_rural: true
438
- 902:
439
- locale: 'Vestmannaeyjar'
440
- dative: 'Vestmannaeyjum'
441
- is_po_box: true