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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 180fb1b19052e02b58dbf01c7436161b5eedf6ac
4
- data.tar.gz: 8c81ab51a7de369e4b67f4aeea9ea92a09d0d0d8
3
+ metadata.gz: 779dac571e0ed045e1288117f563fac6fb3d92ce
4
+ data.tar.gz: b5443b99a7dd60ef870a1699f698b6ff9557911e
5
5
  SHA512:
6
- metadata.gz: 29af7207009e0be13595d161bc45f4b2962f807fe43232690653e08ca475f3b5582bd5e238cc909c9285fa12128a8998f879597f9f87ab779c777252a1c0b972
7
- data.tar.gz: d8e01ff8a7287a3ba46a1cc01f7d4dade778fb7f427b55b1d50a3b6b9f0c09dfa989871dac46cd231c2aba9b3c0d2bb2bc3dde3ead496d1bc277b2de5ff4eadc
6
+ metadata.gz: 6672ed5940fb3607305023a29ab82e42a39e216527dc787a87c77f214edac6c97246487bde497a46b552cdf1b112427129ad67dbf2945781836a73350bc545ba
7
+ data.tar.gz: 1c4e885eb132173a4f5a370a97e1e05754be4dd2ce35fc28eed5b47ef6f6fc043d1802b54c61f0725191ce1cef34ece504f5475b1f2bc737d6df8291ae92520b
data/.travis.yml CHANGED
@@ -2,3 +2,5 @@ language: ruby
2
2
  rvm:
3
3
  - 2.2.3
4
4
  before_install: gem install bundler -v 1.11.2
5
+ notifications:
6
+ email: false
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"
@@ -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] description of returned object
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(/\D/, '')
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)
@@ -1,3 +1,3 @@
1
1
  module Iceland
2
- VERSION = '0.1.7'.freeze
2
+ VERSION = '0.1.8'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iceland
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Vignir