iceland 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/README.md +14 -0
- data/lib/iceland/kennitala.rb +13 -2
- 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: 779dac571e0ed045e1288117f563fac6fb3d92ce
|
4
|
+
data.tar.gz: b5443b99a7dd60ef870a1699f698b6ff9557911e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6672ed5940fb3607305023a29ab82e42a39e216527dc787a87c77f214edac6c97246487bde497a46b552cdf1b112427129ad67dbf2945781836a73350bc545ba
|
7
|
+
data.tar.gz: 1c4e885eb132173a4f5a370a97e1e05754be4dd2ce35fc28eed5b47ef6f6fc043d1802b54c61f0725191ce1cef34ece504f5475b1f2bc737d6df8291ae92520b
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -96,9 +96,23 @@ r = Kennitala.new
|
|
96
96
|
|
97
97
|
# Retrieve the kennitala as a string.
|
98
98
|
# This is a sanitized string, without any non-numeric characters.
|
99
|
+
# Pretty useful when storing it in a database.
|
99
100
|
k.to_s
|
100
101
|
# => "0101302989"
|
101
102
|
|
103
|
+
# Pretty print the kennitala
|
104
|
+
# Adds a space between the 6th and the 7th digits for readability
|
105
|
+
k.pp
|
106
|
+
# => "010130 2989"
|
107
|
+
|
108
|
+
# You can also pass a string to .pp to use as a spacer
|
109
|
+
k.pp('–')
|
110
|
+
# => "010130-2989"
|
111
|
+
|
112
|
+
# You can also pass a cat to the .pp method
|
113
|
+
k.pp('🐈')
|
114
|
+
# => "010130🐈2989"
|
115
|
+
|
102
116
|
# Get the entity type (results in 'person' or 'company')
|
103
117
|
k.entity_type
|
104
118
|
# => "person"
|
data/lib/iceland/kennitala.rb
CHANGED
@@ -90,6 +90,17 @@ class Kennitala
|
|
90
90
|
@value.to_s
|
91
91
|
end
|
92
92
|
|
93
|
+
# Pretty print a kennitala
|
94
|
+
#
|
95
|
+
# Puts a spacer between the 6th and the 7th digit
|
96
|
+
#
|
97
|
+
# @param [String] spacer A single space by default
|
98
|
+
# @return [String]
|
99
|
+
def pp(spacer = ' ')
|
100
|
+
raise ArgumentError 'Spacer must be a string' unless spacer.class == String
|
101
|
+
@value[0, 6] + spacer + @value[6, 9]
|
102
|
+
end
|
103
|
+
|
93
104
|
private
|
94
105
|
|
95
106
|
# Generate fake a birth number and check digit based on the first 6 digits
|
@@ -110,7 +121,7 @@ class Kennitala
|
|
110
121
|
|
111
122
|
# Generate a fake year and century Hash
|
112
123
|
#
|
113
|
-
# @return [Hash]
|
124
|
+
# @return [Hash]
|
114
125
|
def fake_year
|
115
126
|
century = [9, 9, 9, 8, 0, 0].sample
|
116
127
|
current_year = Date.today.strftime('%y').to_i
|
@@ -164,7 +175,7 @@ class Kennitala
|
|
164
175
|
# @param [String] kt_string Unsanitised string representing a kennitala
|
165
176
|
# @return [String, nil] Sanitized kennitala, nil if invalid
|
166
177
|
def sanitize(kt_string)
|
167
|
-
sanitized_kt = kt_string.gsub(
|
178
|
+
sanitized_kt = kt_string.gsub(/[^0-9]/, '')
|
168
179
|
checks = check_checksum(sanitized_kt)
|
169
180
|
|
170
181
|
year = get_year_from_string(sanitized_kt)
|
data/lib/iceland/version.rb
CHANGED