iceland 0.1.12 → 0.1.13
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 +4 -4
- data/README.md +4 -4
- data/lib/iceland/kennitala.rb +51 -5
- data/lib/iceland/postal_codes.rb +1 -0
- data/lib/iceland/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e68b56b4b9a0f44a408049af626052ae90a77f9c
|
4
|
+
data.tar.gz: be1635676c1ba7878caceeddc82285242ba1e9de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3d41d85cf0dc94ce1d2ed1bebb5cc89f0e065890a8534f814857a348ffbe6d880e94a2c822e66c8c444a9807868d260bafcd5c7bda1e391512033b974f56e2d
|
7
|
+
data.tar.gz: 56e62ed486867941cfc7c7c8fe795ba8459d62d71bbde4997a285bbe07eb598956d1dd3e8c9cd0c4c191ee66db7b4451173399de8dd978ac33fb45fc08c48aee
|
data/README.md
CHANGED
@@ -95,7 +95,7 @@ k = Kennitala.new(' 010130-2989')
|
|
95
95
|
|
96
96
|
# Invalid strings are rejected with an argument error
|
97
97
|
f = Kennitala.new('010130-2979')
|
98
|
-
# ArgumentError: Kennitala is invalid
|
98
|
+
# => ArgumentError: Kennitala is invalid
|
99
99
|
|
100
100
|
# If no kennitala string is specified, a random one will be generated
|
101
101
|
r = Kennitala.new
|
@@ -124,11 +124,11 @@ k.pp('🐈')
|
|
124
124
|
k.entity_type
|
125
125
|
# => "person"
|
126
126
|
|
127
|
-
# It's also possible to use .
|
128
|
-
k.
|
127
|
+
# It's also possible to use .company and .person to achieve the same thing
|
128
|
+
k.company?
|
129
129
|
# => false
|
130
130
|
|
131
|
-
k.
|
131
|
+
k.person?
|
132
132
|
# => true
|
133
133
|
|
134
134
|
# Cast the kennitala to a Date object
|
data/lib/iceland/kennitala.rb
CHANGED
@@ -1,10 +1,26 @@
|
|
1
1
|
# The Kennitala Class
|
2
2
|
class Kennitala
|
3
|
-
#
|
3
|
+
# Initialize a Kennitala object
|
4
4
|
#
|
5
|
-
# @
|
6
|
-
#
|
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
|
7
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">
|
8
24
|
def initialize(kt_string = false, is_company = false)
|
9
25
|
kt_string = fake_kt_string(is_company) if kt_string == false
|
10
26
|
unless kt_string.class == String
|
@@ -19,6 +35,12 @@ class Kennitala
|
|
19
35
|
# Get the type of entity - If it is a person or an organization
|
20
36
|
#
|
21
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"
|
22
44
|
def entity_type
|
23
45
|
date_integer = @value[0, 2].to_i
|
24
46
|
return 'person' if date_integer < 32
|
@@ -72,6 +94,12 @@ class Kennitala
|
|
72
94
|
# Get the age of entity in years. Useful when dealing with age restrictions.
|
73
95
|
#
|
74
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
|
75
103
|
def age
|
76
104
|
year_diff = Date.today.year - to_date.year
|
77
105
|
month_diff = Date.today.month - to_date.month
|
@@ -84,23 +112,41 @@ class Kennitala
|
|
84
112
|
# Cast the kennitala to a Date object
|
85
113
|
#
|
86
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)>
|
87
121
|
def to_date
|
88
122
|
Date.new(year, month, day)
|
89
123
|
end
|
90
124
|
|
91
125
|
# Cast the kennitala to a String object
|
92
126
|
#
|
93
|
-
# @return [
|
127
|
+
# @return [String]
|
94
128
|
def to_s
|
95
129
|
@value.to_s
|
96
130
|
end
|
97
131
|
|
98
132
|
# Pretty print a kennitala
|
99
133
|
#
|
100
|
-
#
|
134
|
+
# Adds a space between the 6th and the 7th digits for readability.
|
101
135
|
#
|
102
136
|
# @param [String] spacer A single space by default
|
103
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"
|
104
150
|
def pp(spacer = ' ')
|
105
151
|
raise ArgumentError 'Spacer must be a string' unless spacer.class == String
|
106
152
|
@value[0, 6] + spacer + @value[6, 9]
|
data/lib/iceland/postal_codes.rb
CHANGED
data/lib/iceland/version.rb
CHANGED