iceland 0.1.11 → 0.1.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -6
- data/lib/iceland/kennitala.rb +22 -2
- data/lib/iceland/postal_codes.rb +1 -1
- data/lib/iceland/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ae1e3906373e1c239fb40a8f2bf9c0dd2d47e7d
|
4
|
+
data.tar.gz: f47e1a806270c771ed7f73d0e0c2f2e8db537420
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f41c9b09af2642393e1a10106147c103ef08d05e30dbdce42215688c56e040511667d84f045d14ffb75cf77d21b20ece20a95426f39479124e2448b1fc7212e0
|
7
|
+
data.tar.gz: 11911baf8e643efbb2b2573b69c901b3efd2233cfae15d1d6aacd8aa95bbe0989ec85e0ca6944667d012e0598e57135ce7745b5a3d5e1c589331f4b5afdc9ba7
|
data/README.md
CHANGED
@@ -30,7 +30,7 @@ Icelandic postal codes are 3-digit numeric identifiers, with the first digit ind
|
|
30
30
|
|
31
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
32
|
|
33
|
-
(Note that we use the term "locale" as per Universal Postal Union convention to name town, city or other location the postal code is assigned to.)
|
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
34
|
|
35
35
|
#### Examples
|
36
36
|
|
@@ -62,7 +62,7 @@ Iceland.locale_by_postal_code 311, true
|
|
62
62
|
|
63
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
64
|
|
65
|
-
The class does not access external APIs or databases such National Registry or the Company Registry, so names and status (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.
|
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
66
|
|
67
67
|
#### Uses of kennitala
|
68
68
|
|
@@ -88,8 +88,9 @@ The century identifier has 3 legal values. `8` for the 19th century, `9` for the
|
|
88
88
|
|
89
89
|
```ruby
|
90
90
|
# Initialize a Kennitala object.
|
91
|
-
# The string provided may include spaces and
|
92
|
-
|
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')
|
93
94
|
# => #<Kennitala:0x007fe35d041bc0 @value="0101302989">
|
94
95
|
|
95
96
|
# Invalid strings are rejected with an argument error
|
@@ -143,7 +144,7 @@ k.age
|
|
143
144
|
|
144
145
|
```ruby
|
145
146
|
# Casting a string to a Kennitala object
|
146
|
-
'
|
147
|
+
'010130 2989'.to_kt
|
147
148
|
# => #<Kennitala:0x007fc5893286a0 @value="0101302989">
|
148
149
|
|
149
150
|
# Get the current age based on a String
|
@@ -155,6 +156,7 @@ k.age
|
|
155
156
|
|
156
157
|
* Administrative Divisions
|
157
158
|
* Bank accounts
|
159
|
+
* Car plate numbers
|
158
160
|
|
159
161
|
## About the data
|
160
162
|
|
@@ -172,7 +174,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
172
174
|
|
173
175
|
Bug reports and pull requests are welcome on GitHub at https://github.com/stefanvignir/iceland_gem.
|
174
176
|
|
175
|
-
Do make sure that the `rspec` unit tests run before sending a pull request
|
177
|
+
Do make sure that the `rspec` unit tests run before sending a pull request and write tests for any new functionality you add. Also run `rubocop` to check if your code adheres to the Ruby Style Guide and other conventions.
|
176
178
|
|
177
179
|
## License
|
178
180
|
|
data/lib/iceland/kennitala.rb
CHANGED
@@ -1,9 +1,15 @@
|
|
1
1
|
# The Kennitala Class
|
2
2
|
class Kennitala
|
3
|
+
# Description of method
|
4
|
+
#
|
5
|
+
# @param [String, Boolean] kt_string = false describe kt_string = false
|
6
|
+
# @param [Boolean] is_company = false describe is_company = false
|
7
|
+
# @return [Kennitala] description of returned object
|
3
8
|
def initialize(kt_string = false, is_company = false)
|
4
9
|
kt_string = fake_kt_string(is_company) if kt_string == false
|
5
10
|
unless kt_string.class == String
|
6
|
-
raise ArgumentError, 'Kennitala needs to be provided as a
|
11
|
+
raise ArgumentError, 'Kennitala needs to be provided as a String or '\
|
12
|
+
'Boolean (false)'
|
7
13
|
end
|
8
14
|
sanitised_kt = sanitize(kt_string)
|
9
15
|
raise ArgumentError, 'Kennitala is invalid' if sanitised_kt.nil?
|
@@ -30,7 +36,7 @@ class Kennitala
|
|
30
36
|
|
31
37
|
# Check if the entity is a person
|
32
38
|
#
|
33
|
-
# @return [
|
39
|
+
# @return [Boolean]
|
34
40
|
def person?
|
35
41
|
date_integer = @value[0, 2].to_i
|
36
42
|
return true if date_integer < 32
|
@@ -133,6 +139,8 @@ class Kennitala
|
|
133
139
|
|
134
140
|
# Generate a fake hash that includes randomly generated date elements
|
135
141
|
#
|
142
|
+
# @todo Take leap years into account and thus allow for 29 February
|
143
|
+
#
|
136
144
|
# @param [Boolean] is_company true if the day string is for a company
|
137
145
|
# @return [Hash]
|
138
146
|
def fake_date_hash(is_company = false)
|
@@ -149,6 +157,10 @@ class Kennitala
|
|
149
157
|
month: month.to_s.rjust(2, '0'), day: day.to_s.rjust(2, '0') }
|
150
158
|
end
|
151
159
|
|
160
|
+
# Generate a fake, random kennitala string
|
161
|
+
#
|
162
|
+
# @param [Boolean] is_company If the kennitala is for a company, not a person
|
163
|
+
# @return [String] A 10-digit string representing a kennitala
|
152
164
|
def fake_kt_string(is_company = false)
|
153
165
|
date_hash = fake_date_hash(is_company)
|
154
166
|
randoms_hash = fake_randoms(date_hash)
|
@@ -159,6 +171,10 @@ class Kennitala
|
|
159
171
|
first_six + randoms + date_hash[:century]
|
160
172
|
end
|
161
173
|
|
174
|
+
# Get year from a kennitala string
|
175
|
+
#
|
176
|
+
# @param [String] kt_string Sanitized kennitala string
|
177
|
+
# @return [Fixnum] description of returned object
|
162
178
|
def get_year_from_string(kt_string)
|
163
179
|
century_code = kt_string[9, 1].to_i
|
164
180
|
case century_code
|
@@ -202,6 +218,10 @@ class Kennitala
|
|
202
218
|
checksum
|
203
219
|
end
|
204
220
|
|
221
|
+
# Calculate the check digit for a kennitala
|
222
|
+
#
|
223
|
+
# @param [String] kt_string Sanitized kennitala
|
224
|
+
# @return [Fixnum]
|
205
225
|
def calculate_check_digit(kt_string)
|
206
226
|
remainder = checksum(kt_string).modulo(11)
|
207
227
|
|
data/lib/iceland/postal_codes.rb
CHANGED
@@ -27,7 +27,7 @@ module Iceland
|
|
27
27
|
#
|
28
28
|
# @param [Integer, String] postal_code The postal code
|
29
29
|
# @param [Boolean] force_nominative Display locale name in nomative form
|
30
|
-
# @return [String]
|
30
|
+
# @return [String]
|
31
31
|
def locale_by_postal_code(postal_code, force_nominative = false)
|
32
32
|
postal_code = postal_code.to_i
|
33
33
|
postal_code_hash = POSTAL_CODES[postal_code]
|
data/lib/iceland/version.rb
CHANGED
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.
|
4
|
+
version: 0.1.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Vignir
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|