countries 0.8.4 → 0.9.0

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.
@@ -1,71 +1,71 @@
1
1
  ---
2
2
  AB:
3
- name: "Stockholms län [SE-01]"
4
- names: "Stockholms län [SE-01]"
3
+ name: "Stockholms län"
4
+ names: "Stockholms län"
5
5
  AC:
6
- name: "Västerbottens län [SE-24]"
7
- names: "Västerbottens län [SE-24]"
6
+ name: "Västerbottens län"
7
+ names: "Västerbottens län"
8
8
  BD:
9
- name: "Norrbottens län [SE-25]"
10
- names: "Norrbottens län [SE-25]"
9
+ name: "Norrbottens län"
10
+ names: "Norrbottens län"
11
11
  C:
12
- name: "Uppsala län [SE-03]"
13
- names: "Uppsala län [SE-03]"
12
+ name: "Uppsala län"
13
+ names: "Uppsala län"
14
14
  D:
15
- name: "Södermanlands län [SE-04]"
16
- names: "Södermanlands län [SE-04]"
15
+ name: "Södermanlands län"
16
+ names: "Södermanlands län"
17
17
  E:
18
- name: "Östergötlands län [SE-05]"
19
- names: "Östergötlands län [SE-05]"
18
+ name: "Östergötlands län"
19
+ names: "Östergötlands län"
20
20
  F:
21
- name: "Jönköpings län [SE-06]"
22
- names: "Jönköpings län [SE-06]"
21
+ name: "Jönköpings län"
22
+ names: "Jönköpings län"
23
23
  G:
24
- name: "Kronobergs län [SE-07]"
25
- names: "Kronobergs län [SE-07]"
24
+ name: "Kronobergs län"
25
+ names: "Kronobergs län"
26
26
  H:
27
- name: "Kalmar län [SE-08]"
27
+ name: "Kalmar län"
28
28
  names:
29
29
  - Calmar
30
30
  I:
31
- name: "Gotlands län [SE-09]"
32
- names: "Gotlands län [SE-09]"
31
+ name: "Gotlands län"
32
+ names: "Gotlands län"
33
33
  K:
34
- name: "Blekinge län [SE-10]"
35
- names: "Blekinge län [SE-10]"
34
+ name: "Blekinge län"
35
+ names: "Blekinge län"
36
36
  M:
37
- name: "Skåne län [SE-12]"
37
+ name: "Skåne län"
38
38
  names:
39
39
  - Scania
40
40
  ? "N"
41
41
  :
42
- name: "Hallands län [SE-13]"
43
- names: "Hallands län [SE-13]"
42
+ name: "Hallands län"
43
+ names: "Hallands län"
44
44
  O:
45
- name: "Västra Götalands län [SE-14]"
46
- names: "Västra Götalands län [SE-14]"
45
+ name: "Västra Götalands län"
46
+ names: "Västra Götalands län"
47
47
  S:
48
- name: "Värmlands län [SE-17]"
49
- names: "Värmlands län [SE-17]"
48
+ name: "Värmlands län"
49
+ names: "Värmlands län"
50
50
  T:
51
- name: "Örebro län [SE-18]"
52
- names: "Örebro län [SE-18]"
51
+ name: "Örebro län"
52
+ names: "Örebro län"
53
53
  U:
54
- name: "Västmanlands län [SE-19]"
55
- names: "Västmanlands län [SE-19]"
54
+ name: "Västmanlands län"
55
+ names: "Västmanlands län"
56
56
  W:
57
- name: "Dalarnas län [SE-20]"
57
+ name: "Dalarnas län"
58
58
  names:
59
59
  - Dalarnas
60
60
  - Dalecarlia
61
61
  - Kopparberg
62
62
  X:
63
- name: "Gävleborgs län [SE-21]"
64
- names: "Gävleborgs län [SE-21]"
63
+ name: "Gävleborgs län"
64
+ names: "Gävleborgs län"
65
65
  ? "Y"
66
66
  :
67
- name: "Västernorrlands län [SE-22]"
68
- names: "Västernorrlands län [SE-22]"
67
+ name: "Västernorrlands län"
68
+ names: "Västernorrlands län"
69
69
  Z:
70
- name: "Jämtlands län [SE-23]"
71
- names: "Jämtlands län [SE-23]"
70
+ name: "Jämtlands län"
71
+ names: "Jämtlands län"
data/spec/country_spec.rb CHANGED
@@ -34,6 +34,10 @@ describe ISO3166::Country do
34
34
  country.longitude.should == '97 00 W'
35
35
  end
36
36
 
37
+ it "should return continent" do
38
+ country.continent.should == "North America"
39
+ end
40
+
37
41
  it 'should return region' do
38
42
  country.region.should == 'Americas'
39
43
  end
@@ -41,11 +45,11 @@ describe ISO3166::Country do
41
45
  it 'should return subregion' do
42
46
  country.subregion.should == 'Northern America'
43
47
  end
44
-
48
+
45
49
  it 'should return ioc code' do
46
50
  country.ioc.should == 'USA'
47
51
  end
48
-
52
+
49
53
  it 'should return UN/LOCODE' do
50
54
  country.un_locode.should == 'US'
51
55
  end
@@ -93,7 +97,7 @@ describe ISO3166::Country do
93
97
  country.states.should have(57).states
94
98
  end
95
99
  end
96
-
100
+
97
101
  describe 'valid?' do
98
102
  it 'should return true if country is valid' do
99
103
  ISO3166::Country.new('US').should be_valid
@@ -103,22 +107,30 @@ describe ISO3166::Country do
103
107
  ISO3166::Country.new('fubar').should_not be_valid
104
108
  end
105
109
  end
106
-
110
+
107
111
  describe 'all' do
108
112
  it 'should return an arry list of all countries' do
109
113
  countries = ISO3166::Country.all
110
114
  countries.should be_an(Array)
111
115
  countries.first.should be_an(Array)
112
- countries.should have(246).countries
116
+ countries.should have(247).countries
117
+ end
118
+
119
+ it "should allow to customize each country representation passing a block to the method" do
120
+ countries = ISO3166::Country.all { |country, data| [data['name'], country, data['country_code'] ] }
121
+ countries.should be_an(Array)
122
+ countries.first.should be_an(Array)
123
+ countries.first.should have(3).fields
124
+ countries.should have(247).countries
113
125
  end
114
126
  end
115
-
127
+
116
128
  describe 'countries' do
117
129
  it 'should be the same as all' do
118
130
  ISO3166::Country.countries.should == ISO3166::Country.all
119
131
  end
120
132
  end
121
-
133
+
122
134
  describe 'search' do
123
135
  it 'should return new country object when a valid alpha2 string is passed' do
124
136
  ISO3166::Country.search('US').should be_a(ISO3166::Country)
@@ -144,7 +156,7 @@ describe ISO3166::Country do
144
156
 
145
157
  it 'should allow access to symbol' do
146
158
  country.currency[:symbol].should == '$'
147
- end
159
+ end
148
160
  end
149
161
 
150
162
  describe "Country class" do
@@ -171,6 +183,50 @@ describe ISO3166::Country do
171
183
  end
172
184
  end
173
185
 
186
+ describe 'find_all_by' do
187
+ context "when searchead attribute equals the given value" do
188
+ let(:spain_data) { ISO3166::Country.find_all_by('alpha2', "ES") }
189
+
190
+ it "returns a hash with the data of the country" do
191
+ spain_data.should be_a Hash
192
+ spain_data.should have(1).keys
193
+ end
194
+ end
195
+
196
+ context "when searchead attribute is list and one of its elements equals the given value" do
197
+ let(:spain_data) { ISO3166::Country.find_all_by('languages', "en") }
198
+
199
+ it "returns a hash with the data of the country" do
200
+ spain_data.should be_a Hash
201
+ spain_data.size.should > 1
202
+ end
203
+ end
204
+
205
+ it "also finds results if the given values is not upcased/downcased properly" do
206
+ spain_data = ISO3166::Country.find_all_by('alpha2', "es")
207
+ spain_data.should be_a Hash
208
+ spain_data.should have(1).keys
209
+ end
210
+
211
+ it "also finds results if the attribute is given as a symbol" do
212
+ spain_data = ISO3166::Country.find_all_by(:alpha2, "ES")
213
+ spain_data.should be_a Hash
214
+ spain_data.should have(1).keys
215
+ end
216
+
217
+ it "casts the given value to a string to perform the search" do
218
+ spain_data = ISO3166::Country.find_all_by(:country_code, 34)
219
+ spain_data.should be_a Hash
220
+ spain_data.keys.should == ['ES']
221
+ end
222
+
223
+ it "also performs searches with regexps and forces it to ignore case" do
224
+ spain_data = ISO3166::Country.find_all_by(:names, /Españ/)
225
+ spain_data.should be_a Hash
226
+ spain_data.keys.should == ['ES']
227
+ end
228
+ end
229
+
174
230
  describe "hash finder methods" do
175
231
  context "when search name in 'name'" do
176
232
  subject { ISO3166::Country.find_by_name("Poland") }
@@ -189,13 +245,13 @@ describe ISO3166::Country do
189
245
 
190
246
  its(:first) { should == "PL" }
191
247
  end
192
-
248
+
193
249
  context "when finding by invalid attribute" do
194
250
  it "should raise an error" do
195
251
  lambda { ISO3166::Country.find_by_invalid('invalid') }.should raise_error
196
252
  end
197
253
  end
198
-
254
+
199
255
  context "when using find_all method" do
200
256
  let(:list) { ISO3166::Country.find_all_by_currency('USD') }
201
257
 
@@ -204,15 +260,14 @@ describe ISO3166::Country do
204
260
  list.first.should be_a(Array)
205
261
  end
206
262
  end
207
-
263
+
208
264
  context "when using find_by method" do
209
265
  subject { ISO3166::Country.find_by_alpha3('CAN') }
210
-
266
+
211
267
  its(:length) { should == 2 }
212
268
  its(:first) { should be_a(String) }
213
269
  its(:last) { should be_a(Hash) }
214
270
  end
215
-
216
271
  end
217
272
 
218
273
  describe "country finder methods" do
@@ -241,13 +296,13 @@ describe ISO3166::Country do
241
296
  bogus.should == nil
242
297
  end
243
298
  end
244
-
299
+
245
300
  context "when finding by invalid attribute" do
246
301
  it "should raise an error" do
247
302
  lambda { ISO3166::Country.find_country_by_invalid('invalid') }.should raise_error
248
303
  end
249
304
  end
250
-
305
+
251
306
  context "when using find_all method" do
252
307
  let(:list) { ISO3166::Country.find_all_countries_by_currency('USD') }
253
308
 
@@ -256,10 +311,10 @@ describe ISO3166::Country do
256
311
  list.first.should be_a(ISO3166::Country)
257
312
  end
258
313
  end
259
-
314
+
260
315
  context "when using find_by method" do
261
316
  let(:country) { ISO3166::Country.find_country_by_alpha3('CAN') }
262
-
317
+
263
318
  it 'should be a single country object' do
264
319
  country.should be_a(ISO3166::Country)
265
320
  end
@@ -275,10 +330,10 @@ describe ISO3166::Country do
275
330
  names.size.should == names.uniq.size
276
331
  end
277
332
  end
278
-
333
+
279
334
  describe 'Norway' do
280
335
  let(:norway) { ISO3166::Country.search('NO') }
281
-
336
+
282
337
  it 'should have a currency' do
283
338
  norway.currency.should be_a(ISO4217::Currency)
284
339
  end
@@ -291,5 +346,4 @@ describe ISO3166::Country do
291
346
  german_speaking_countries.size.should == 6
292
347
  end
293
348
  end
294
-
295
349
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: countries
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.4
4
+ version: 0.9.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-11-06 00:00:00.000000000 Z
13
+ date: 2013-02-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: currencies
@@ -300,7 +300,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
300
300
  version: '0'
301
301
  requirements: []
302
302
  rubyforge_project:
303
- rubygems_version: 1.8.24
303
+ rubygems_version: 1.8.23
304
304
  signing_key:
305
305
  specification_version: 3
306
306
  summary: Gives you a country object full of all sorts of useful information.