iceland 0.1.12 → 0.1.13

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: 8ae1e3906373e1c239fb40a8f2bf9c0dd2d47e7d
4
- data.tar.gz: f47e1a806270c771ed7f73d0e0c2f2e8db537420
3
+ metadata.gz: e68b56b4b9a0f44a408049af626052ae90a77f9c
4
+ data.tar.gz: be1635676c1ba7878caceeddc82285242ba1e9de
5
5
  SHA512:
6
- metadata.gz: f41c9b09af2642393e1a10106147c103ef08d05e30dbdce42215688c56e040511667d84f045d14ffb75cf77d21b20ece20a95426f39479124e2448b1fc7212e0
7
- data.tar.gz: 11911baf8e643efbb2b2573b69c901b3efd2233cfae15d1d6aacd8aa95bbe0989ec85e0ca6944667d012e0598e57135ce7745b5a3d5e1c589331f4b5afdc9ba7
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 .is_company and .is_person to achieve the same thing
128
- k.is_company?
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.is_person?
131
+ k.person?
132
132
  # => true
133
133
 
134
134
  # Cast the kennitala to a Date object
@@ -1,10 +1,26 @@
1
1
  # The Kennitala Class
2
2
  class Kennitala
3
- # Description of method
3
+ # Initialize a Kennitala object
4
4
  #
5
- # @param [String, Boolean] kt_string = false describe kt_string = false
6
- # @param [Boolean] is_company = false describe is_company = false
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 [Date]
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
- # Puts a spacer between the 6th and the 7th digit
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]
@@ -1,5 +1,6 @@
1
1
  # Postal Codes
2
2
  module Iceland
3
+ # The postal code data as a Hash object
3
4
  POSTAL_CODES = YAML.load_file(File.expand_path('../../postcodes.yml',
4
5
  __FILE__))
5
6
 
@@ -1,3 +1,3 @@
1
1
  module Iceland
2
- VERSION = '0.1.12'.freeze
2
+ VERSION = '0.1.13'.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.12
4
+ version: 0.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Vignir