locations_ng 0.0.1 → 0.0.3

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: 282b93b280281c57d3d7b50adb6d8c090aad83ab
4
- data.tar.gz: 2831e484cd23fce416c48a4de9c0133d54f7698e
3
+ metadata.gz: 13638137e9d4048e7fed3d8dbdb1deb1882831fd
4
+ data.tar.gz: b0bc09942b1cc6a91ecde3f3b7c5fc328427fec2
5
5
  SHA512:
6
- metadata.gz: d645d7f13e59cbe8d2b4c8bbe0ee8a3254f6a4000a8597d0957085e03cecdeef8fb8fd18f3697e2cdc1a2df78bcb57d2f568236694af04c2db5b063c88a2ee6d
7
- data.tar.gz: c8aea22c9cc770d9d13d4c5bf180a260fd39545e13c071982ca8da2ea4a29d0dfc8add89b3db609389df963067e15692cc60844aff0d0b0016c536b2e56bd31d
6
+ metadata.gz: fe47a5238748be0c1d4fe7a0ee056ec212e06dc7aff2a84923fe6be1cc22330e2af004e415b67571d71c213e2d5e78a462ae8ded37a817ea5d74397c26a5c3ba
7
+ data.tar.gz: 336ea084da2989c54854988be9462a9e62e798f7d15f789682ef00d620c717ad6000768e64098c73510b2f6a54ea45cf6624a2ca7887c1f0c304ef78537ebc75
@@ -0,0 +1,28 @@
1
+ module LocationsNg
2
+ class City
3
+ def all
4
+ load_cities
5
+ end
6
+
7
+ def cities(state)
8
+ state = state.downcase.gsub(' ', '_')
9
+ city_index = load_cities.index{|c| c['alias'] == state}
10
+
11
+ if city_index.nil?
12
+ {message: "No cities found for '#{state}'", status: 404}
13
+ else
14
+ load_cities[city_index]['cities']
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def load_cities
21
+ YAML.load(File.read(files_location 'cities'))
22
+ end
23
+
24
+ def files_location(file)
25
+ File.expand_path("../locations/#{file}.yml", __FILE__)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,20 @@
1
+ module LocationsNg
2
+ class Lga
3
+ def lgas(state)
4
+ state = state.downcase.gsub(' ', '_')
5
+
6
+ res = load_lgas.map{|l| l[0] if l[1] == state.capitalize}.compact
7
+ res.empty? ? {message: "No lgas found for '#{state}'", :status=>404} : res
8
+ end
9
+
10
+ private
11
+
12
+ def load_lgas
13
+ YAML.load(File.read(files_location 'lgas'))
14
+ end
15
+
16
+ def files_location(file)
17
+ File.expand_path("../locations/#{file}.yml", __FILE__)
18
+ end
19
+ end
20
+ end
@@ -1,81 +1,132 @@
1
1
  ---
2
- - - Eket
3
- - Akwa Ibom
4
- - - Ikot Ekpene
5
- - Akwa Ibom
6
- - - Oron
7
- - Akwa Ibom
8
- - - Uyo
9
- - Akwa Ibom
10
- - - Bauchi
11
- - Bauchi
12
- - - Makurdi
13
- - Benue
14
- - - Bama
15
- - Borno
16
- - - Maiduguri
17
- - Borno
18
- - - Yenagoa
19
- - Bayelsa
20
- - - Sapele
21
- - Delta
22
- - - Abakaliki
23
- - Ebonyi
24
- - - Ado Ekiti
25
- - Ekiti
26
- - - Nsukka
27
- - Enugu
28
- - - Gombe
29
- - Gombe
30
- - - Dutse
31
- - Jigawa
32
- - - Okigwe
33
- - Imo
34
- - - Orlu
35
- - Imo
36
- - - Zaria
37
- - Kaduna
38
- - - Birnin Kebbi
39
- - Kebbi
40
- - - Lokoja
41
- - Kogi
42
- - - Okene
43
- - Kogi
44
- - - Agege
45
- - Lagos
46
- - - Ikeja
47
- - Lagos
48
- - - Funtua
49
- - Katsina
50
- - - Katsina
51
- - Katsina
52
- - - Offa
53
- - Kwara
54
- - - Lafia
55
- - Nasarawa
56
- - - Bida
57
- - Niger
58
- - - Suleja
59
- - Niger
60
- - - Ijebu Ode
61
- - Ogun
62
- - - Shagamu
63
- - Ogun
64
- - - Owo
65
- - Ondo
66
- - - Port Harcourt
67
- - Rivers
68
- - - Oyo
69
- - Oyo
70
- - - Iwo
71
- - Osun
72
- - - Osogbo
73
- - Osun
74
- - - Wukari
75
- - Taraba
76
- - - Nguru
77
- - Yobe
78
- - - Potiskum
79
- - Yobe
80
- - - Gusau
81
- - Zamfara
2
+ - state: Akwa Ibom
3
+ alias: akwa_ibom
4
+ cities:
5
+ - Eket
6
+ - Ikot Ekpene
7
+ - Oron
8
+ - Uyo
9
+ - state: Bauchi
10
+ alias: bauchi
11
+ cities:
12
+ - Bauchi
13
+ - state: Benue
14
+ alias: benue
15
+ cities:
16
+ - Makurdi
17
+ - state: Borno
18
+ alias: borno
19
+ cities:
20
+ - Bama
21
+ - Maiduguri
22
+ - state: Bayelsa
23
+ alias: bayelsa
24
+ cities:
25
+ - Yenagoa
26
+ - state: Delta
27
+ alias: delta
28
+ cities:
29
+ - Sapele
30
+ - state: Ebonyi
31
+ alias: ebonyi
32
+ cities:
33
+ - Abakaliki
34
+ - state: Ekiti
35
+ alias: ekiti
36
+ cities:
37
+ - Ado Ekiti
38
+ - state: Enugu
39
+ alias: enugu
40
+ cities:
41
+ - Enugu
42
+ - Nsukka
43
+ - Agbani
44
+ - Awgu
45
+ - Udi
46
+ - Oji-River
47
+ - state: Gombe
48
+ alias: gombe
49
+ cities:
50
+ - Gombe
51
+ - state: Jigawa
52
+ alias: jigawa
53
+ cities:
54
+ - Dutse
55
+ - state: Imo
56
+ alias: imo
57
+ cities:
58
+ - Okigwe
59
+ - Orlu
60
+ - state: Kaduna
61
+ alias: kaduna
62
+ cities:
63
+ - Kaduna
64
+ - Zaria
65
+ - state: Kebbi
66
+ alias: kebbi
67
+ cities:
68
+ - Birnin Kebbi
69
+ - state: Kogi
70
+ alias: kogi
71
+ cities:
72
+ - Lokoja
73
+ - Okene
74
+ - state: Lagos
75
+ alias: lagos
76
+ cities:
77
+ - Agege
78
+ - Ikeja
79
+ - state: Katsina
80
+ alias: katsina
81
+ cities:
82
+ - Funtua
83
+ - Katsina
84
+ - state: Kwara
85
+ alias: kwara
86
+ cities:
87
+ - Offa
88
+ - Ilorin
89
+ - state: Nasarawa
90
+ alias: nasarawa
91
+ cities:
92
+ - Lafia
93
+ - state: Niger
94
+ alias: niger
95
+ cities:
96
+ - Bida
97
+ - Suleja
98
+ - state: Ogun
99
+ alias: ogun
100
+ cities:
101
+ - Ijebu Ode
102
+ - Shagamu
103
+ - state: Ondo
104
+ alias: ondo
105
+ cities:
106
+ - Owo
107
+ - state: Rivers
108
+ alias: rivers
109
+ cities:
110
+ - Port Harcourt
111
+ - state: Oyo
112
+ alias: oyo
113
+ cities:
114
+ - Oyo
115
+ - state: Osun
116
+ alias: osun
117
+ cities:
118
+ - Iwo
119
+ - Osogbo
120
+ - state: Taraba
121
+ alias: taraba
122
+ cities:
123
+ - Wukari
124
+ - state: Yobe
125
+ alias: yobe
126
+ cities:
127
+ - Nguru
128
+ - Potiskum
129
+ - state: Zamfara
130
+ alias: zamfara
131
+ cities:
132
+ - Gusau
@@ -7,6 +7,7 @@
7
7
  maxLat: 6.0191921
8
8
  longitude: 7.524724300000001
9
9
  maxLong: 7.9630091
10
+ alias: abia
10
11
  - minLat: 7.452592
11
12
  name: Adamawa
12
13
  capital: Yola
@@ -15,6 +16,7 @@
15
16
  maxLat: 10.943588
16
17
  longitude: 12.4380581
17
18
  maxLong: 13.6924919
19
+ alias: adamawa
18
20
  - minLat: 4.4780049
19
21
  name: Akwa Ibom
20
22
  capital: Uyo
@@ -23,6 +25,7 @@
23
25
  maxLat: 5.530245
24
26
  longitude: 7.872159999999999
25
27
  maxLong: 8.340371
28
+ alias: akwa_ibom
26
29
  - minLat: 5.692615000000001
27
30
  name: Anambra
28
31
  capital: Awka
@@ -31,6 +34,7 @@
31
34
  maxLat: 6.7795999
32
35
  longitude: 7.0068393
33
36
  maxLong: 7.355934
37
+ alias: anambra
34
38
  - minLat: 10.255381
35
39
  name: Bauchi
36
40
  capital: Bauchi
@@ -39,6 +43,7 @@
39
43
  maxLat: 10.3398292
40
44
  longitude: 9.844166999999999
41
45
  maxLong: 9.864006
46
+ alias: bauchi
42
47
  - minLat: 6.4427789
43
48
  name: Benue
44
49
  capital: Makurdi
@@ -47,6 +52,7 @@
47
52
  maxLat: 8.149299
48
53
  longitude: 8.8362755
49
54
  maxLong: 9.918301
55
+ alias: benue
50
56
  - minLat: 10.0291549
51
57
  name: Borno
52
58
  capital: Maiduguri
@@ -55,6 +61,7 @@
55
61
  maxLat: 13.7144441
56
62
  longitude: 12.9789121
57
63
  maxLong: 14.680073
64
+ alias: borno
58
65
  - minLat: 4.2771439
59
66
  name: Bayelsa
60
67
  capital: Yenagoa
@@ -63,6 +70,7 @@
63
70
  maxLat: 5.3933139
64
71
  longitude: 5.898713900000001
65
72
  maxLong: 6.724865899999999
73
+ alias: bayelsa
66
74
  - minLat: 4.690596000000001
67
75
  name: Cross River
68
76
  capital: Calabar
@@ -71,6 +79,7 @@
71
79
  maxLat: 6.899680999999999
72
80
  longitude: 8.6600586
73
81
  maxLong: 9.472486
82
+ alias: cross_river
74
83
  - minLat: 5.024351999999999
75
84
  name: Delta
76
85
  capital: Asaba
@@ -79,6 +88,7 @@
79
88
  maxLat: 6.5248195
80
89
  longitude: 5.898713900000001
81
90
  maxLong: 6.7653911
91
+ alias: delta
82
92
  - minLat: 5.6873539
83
93
  name: Ebonyi
84
94
  capital: Abakaliki
@@ -87,6 +97,7 @@
87
97
  maxLat: 6.807093
88
98
  longitude: 7.959286299999999
89
99
  maxLong: 8.4470269
100
+ alias: ebonyi
90
101
  - minLat: 5.7386799
91
102
  name: Edo
92
103
  capital: Benin
@@ -95,6 +106,7 @@
95
106
  maxLat: 7.5721479
96
107
  longitude: 5.898713900000001
97
108
  maxLong: 6.707891000000001
109
+ alias: edo
98
110
  - minLat: 7.272215999999999
99
111
  name: Ekiti
100
112
  capital: Ado-Ekiti
@@ -103,6 +115,7 @@
103
115
  maxLat: 8.0674911
104
116
  longitude: 5.3102505
105
117
  maxLong: 5.8048959
118
+ alias: ekiti
106
119
  - minLat: 6.360852
107
120
  name: Enugu
108
121
  capital: Enugu
@@ -111,6 +124,7 @@
111
124
  maxLat: 6.5155669
112
125
  longitude: 7.510332999999998
113
126
  maxLong: 7.618160199999999
127
+ alias: enugu
114
128
  - minLat: 8.396675
115
129
  name: Federal Capital Territory
116
130
  capital: Abuja
@@ -119,6 +133,7 @@
119
133
  maxLat: 9.3574219
120
134
  longitude: 7.179025999999999
121
135
  maxLong: 7.617400000000001
136
+ alias: abuja
122
137
  - minLat: 10.264117
123
138
  name: Gombe
124
139
  capital: Gombe
@@ -127,6 +142,7 @@
127
142
  maxLat: 10.3128497
128
143
  longitude: 11.166667
129
144
  maxLong: 11.2147019
145
+ alias: gombe
130
146
  - minLat: 12.5688205
131
147
  name: Jigawa
132
148
  capital: Dutse
@@ -135,6 +151,7 @@
135
151
  maxLat: 12.5708993
136
152
  longitude: 8.9400589
137
153
  maxLong: 8.9410364
154
+ alias: jigawa
138
155
  - minLat: 5.179824000000001
139
156
  name: Imo
140
157
  capital: Owerri
@@ -143,6 +160,7 @@
143
160
  maxLat: 5.928465
144
161
  longitude: 6.920913499999999
145
162
  maxLong: 7.404109
163
+ alias: imo
146
164
  - minLat: 10.3971566
147
165
  name: Kaduna
148
166
  capital: Kaduna
@@ -151,6 +169,7 @@
151
169
  maxLat: 10.6169963
152
170
  longitude: 7.433332999999999
153
171
  maxLong: 7.508812000000001
172
+ alias: kaduna
154
173
  - minLat: 10.0931591
155
174
  name: Kebbi
156
175
  capital: Birnin Kebbi
@@ -159,6 +178,7 @@
159
178
  maxLat: 13.232542
160
179
  longitude: 4.0695454
161
180
  maxLong: 6.027123
181
+ alias: kebbi
162
182
  - minLat: 11.912873
163
183
  name: Kano
164
184
  capital: Kano
@@ -167,6 +187,7 @@
167
187
  maxLat: 12.0829016
168
188
  longitude: 8.591956099999999
169
189
  maxLong: 8.6704765
190
+ alias: kano
170
191
  - minLat: 6.528274199999999
171
192
  name: Kogi
172
193
  capital: Lokoja
@@ -175,6 +196,7 @@
175
196
  maxLat: 8.7320238
176
197
  longitude: 6.5783387
177
198
  maxLong: 7.8822179
199
+ alias: kogi
178
200
  - minLat: 6.3936419
179
201
  name: Lagos
180
202
  capital: Ikeja
@@ -183,6 +205,7 @@
183
205
  maxLat: 6.7027984
184
206
  longitude: 3.3792057
185
207
  maxLong: 3.696727799999999
208
+ alias: lagos
186
209
  - minLat: 12.934095
187
210
  name: Katsina
188
211
  capital: Katsina
@@ -191,6 +214,7 @@
191
214
  maxLat: 13.0357094
192
215
  longitude: 7.6
193
216
  maxLong: 7.676266000000001
217
+ alias: katsina
194
218
  - minLat: 7.966079000000001
195
219
  name: Kwara
196
220
  capital: Ilorin
@@ -199,6 +223,7 @@
199
223
  maxLat: 10.152084
200
224
  longitude: 4.5624426
201
225
  maxLong: 6.2142591
226
+ alias: kwara
202
227
  - minLat: 7.769181
203
228
  name: Nasarawa
204
229
  capital: Lafia
@@ -207,6 +232,7 @@
207
232
  maxLat: 9.365964000000002
208
233
  longitude: 8.3088441
209
234
  maxLong: 9.605724
235
+ alias: nasarawa
210
236
  - minLat: 4.269857099999999
211
237
  name: Niger
212
238
  capital: Minna
@@ -215,6 +241,7 @@
215
241
  maxLat: 13.885645
216
242
  longitude: 8.675277
217
243
  maxLong: 14.677982
244
+ alias: niger
218
245
  - minLat: 6.315346099999999
219
246
  name: Ogun
220
247
  capital: Abeokuta
@@ -223,6 +250,7 @@
223
250
  maxLat: 7.974634999999999
224
251
  longitude: 3.2583626
225
252
  maxLong: 4.5990951
253
+ alias: ogun
226
254
  - minLat: 7.0529381
227
255
  name: Ondo
228
256
  capital: Akure
@@ -231,6 +259,7 @@
231
259
  maxLat: 7.1249106
232
260
  longitude: 4.833333
233
261
  maxLong: 4.871921599999999
262
+ alias: ondo
234
263
  - minLat: 4.347035099999999
235
264
  name: Rivers
236
265
  capital: Port Harcourt
@@ -239,6 +268,7 @@
239
268
  maxLat: 5.694652899999999
240
269
  longitude: 6.920913499999999
241
270
  maxLong: 7.591592899999998
271
+ alias: rivers
242
272
  - minLat: 7.790425099999999
243
273
  name: Oyo
244
274
  capital: Ibadan
@@ -247,6 +277,7 @@
247
277
  maxLat: 7.8899933
248
278
  longitude: 3.933
249
279
  maxLong: 3.9751624
280
+ alias: oyo
250
281
  - minLat: 6.969976
251
282
  name: Osun
252
283
  capital: Osogbo
@@ -255,6 +286,7 @@
255
286
  maxLat: 8.088640999999999
256
287
  longitude: 4.5624426
257
288
  maxLong: 5.0647019
289
+ alias: osun
258
290
  - minLat: 12.9764148
259
291
  name: Sokoto
260
292
  capital: Sokoto
@@ -263,6 +295,7 @@
263
295
  maxLat: 13.0880893
264
296
  longitude: 5.233333
265
297
  maxLong: 5.2881144
298
+ alias: sokoto
266
299
  - minLat: 8.350639
267
300
  name: Plateau
268
301
  capital: Jos
@@ -271,6 +304,7 @@
271
304
  maxLat: 10.3447241
272
305
  longitude: 9.7232673
273
306
  maxLong: 10.6606639
307
+ alias: plateau
274
308
  - minLat: 6.502453999999999
275
309
  name: Taraba
276
310
  capital: Jalingo
@@ -279,6 +313,7 @@
279
313
  maxLat: 9.604444899999999
280
314
  longitude: 10.9807003
281
315
  maxLong: 11.981274
316
+ alias: taraba
282
317
  - minLat: 10.5932052
283
318
  name: Yobe
284
319
  capital: Damaturu
@@ -287,6 +322,7 @@
287
322
  maxLat: 13.376133
288
323
  longitude: 11.7068294
289
324
  maxLong: 12.494047
325
+ alias: yobe
290
326
  - minLat: 10.854616
291
327
  name: Zamfara
292
328
  capital: Gusau
@@ -295,3 +331,4 @@
295
331
  maxLat: 13.207291
296
332
  longitude: 6.2375947
297
333
  maxLong: 7.245729999999999
334
+ alias: zamfara
@@ -1,19 +1,42 @@
1
1
  module LocationsNg
2
2
  class State
3
- attr_accessor :state
3
+ def all
4
+ load_states.map{ |s| {name: s['name'], capital: s['capital']} }
5
+ end
6
+
7
+ def details(state)
8
+ state = state.downcase.gsub(' ', '_')
9
+ all_states = load_states
10
+
11
+ state_index = all_states.index{|s| s['alias'] == state}
4
12
 
5
- def initialize(state = 'all')
6
- @state = state
13
+ if state_index.nil?
14
+ {message: "No state found for '#{state}'", status: 404}
15
+ else
16
+ res = all_states[state_index].with_indifferent_access
17
+ res['cities'] = LocationsNg::City.new.cities(state)
18
+ res['lgas'] = LocationsNg::Lga.new.lgas(state)
19
+ res
20
+ end
7
21
  end
8
22
 
9
- def states
10
- load_yaml('states').map { |s| {name: s['name'], capital: s['capital']} }
23
+ def capital(state)
24
+ state = state.downcase.gsub(' ', '_')
25
+ all_states = load_states
26
+
27
+ state_index = all_states.index{|s| s['alias'] == state}
28
+
29
+ if state_index.nil?
30
+ {message: "No state found for '#{state}'", status: 404}
31
+ else
32
+ all_states[state_index]['capital']
33
+ end
11
34
  end
12
35
 
13
36
  private
14
37
 
15
- def load_yaml(file)
16
- YAML.load(File.read(files_location file))
38
+ def load_states
39
+ YAML.load(File.read(files_location 'states'))
17
40
  end
18
41
 
19
42
  def files_location(file)
@@ -1,3 +1,3 @@
1
1
  module LocationsNg
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.3'
3
3
  end
data/lib/locations_ng.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  require 'yaml'
2
+ require 'active_support/core_ext/hash/indifferent_access'
2
3
  require 'locations_ng/state'
4
+ require 'locations_ng/city'
5
+ require 'locations_ng/lga'
3
6
 
4
7
  module LocationsNg
5
8
  end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ module LocationsNg
4
+ describe City do
5
+ let(:city) { LocationsNg::City.new }
6
+
7
+ describe '.all' do
8
+ let(:cities_response) { File.read('spec/responses/cities.json') }
9
+
10
+ it 'returns all cities' do
11
+ expect(city.all).to eq(JSON.parse(cities_response))
12
+ end
13
+ end
14
+
15
+ describe '.cities' do
16
+ context 'when state is not found' do
17
+ it 'returns error message' do
18
+ expect(city.cities('Invalid State')).to eq({message: "No cities found for 'invalid_state'", status: 404})
19
+ end
20
+ end
21
+
22
+ context 'when state is found' do
23
+ it 'returns the cities of a specific state' do
24
+ expect(city.cities('Akwa Ibom')).to eq(['Eket', 'Ikot Ekpene', 'Oron', 'Uyo'])
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ module LocationsNg
4
+ describe Lga do
5
+ let(:lga) { LocationsNg::Lga.new }
6
+
7
+ describe '.lgas' do
8
+ context 'when lgas for a state is not found' do
9
+ it 'returns an error message' do
10
+ expect(lga.lgas('Unknown State')).to eq({message: "No lgas found for 'unknown_state'", status: 404})
11
+ end
12
+ end
13
+
14
+ context 'when state is found' do
15
+ it 'returns the lgas for state' do
16
+ expect(lga.lgas('Lagos')).to eq(['Agege', 'Ajeromi-Ifelodun', 'Alimosho',
17
+ 'Amuwo-Odofin', 'Badagry', 'Apapa', 'Epe',
18
+ 'Eti Osa', 'Ibeju-Lekki', 'Ifako-Ijaiye',
19
+ 'Ikeja', 'Ikorodu', 'Kosofe', 'Lagos Island',
20
+ 'Mushin', 'Lagos Mainland', 'Ojo', 'Oshodi-Isolo',
21
+ 'Shomolu', 'Surulere Lagos State'])
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -2,26 +2,61 @@ require 'spec_helper'
2
2
 
3
3
  module LocationsNg
4
4
  describe State do
5
- describe '.initialize' do
6
- context 'when no argument is passed' do
7
- let(:state) { LocationsNg::State.new }
5
+ let(:state) { LocationsNg::State.new }
8
6
 
9
- it 'state is "all"' do
10
- expect(state.state).to eq('all')
11
- end
12
- end
13
- end
14
-
15
- describe '.states' do
16
- let(:state) { LocationsNg::State.new }
7
+ describe '.all' do
17
8
  let(:state_response) { File.read('spec/responses/canonical_states.json') }
18
9
 
19
10
  it 'returns 37 states' do
20
- expect(state.states.count).to eq(37)
11
+ expect(state.all.count).to eq(37)
21
12
  end
22
13
 
23
14
  it 'returns all canonical states, with name and capital' do
24
- expect(state.states).to eq(JSON.parse(state_response, symbolize_names: true))
15
+ expect(state.all).to eq(JSON.parse(state_response, symbolize_names: true))
16
+ end
17
+ end
18
+
19
+ describe '.details' do
20
+ context 'when state is not found' do
21
+ it 'returns status with message' do
22
+ expect(state.details('AbIja')).to eq({message: "No state found for 'abija'", status: 404})
23
+ end
24
+ end
25
+
26
+ context 'when state is found' do
27
+ it 'returns detailed data for the state' do
28
+ expect(state.details('Lagos')).to eq({'minLat'=>6.3936419,
29
+ 'name'=>'Lagos',
30
+ 'capital'=>'Ikeja',
31
+ 'latitude'=>6.5243793,
32
+ 'minLong'=>3.0982732,
33
+ 'maxLat'=>6.7027984,
34
+ 'longitude'=>3.3792057,
35
+ 'maxLong'=>3.696727799999999,
36
+ 'alias'=>'lagos',
37
+ 'cities'=>%w(Agege Ikeja),
38
+ 'lgas'=>['Agege', 'Ajeromi-Ifelodun', 'Alimosho',
39
+ 'Amuwo-Odofin', 'Badagry', 'Apapa', 'Epe',
40
+ 'Eti Osa', 'Ibeju-Lekki', 'Ifako-Ijaiye',
41
+ 'Ikeja', 'Ikorodu', 'Kosofe', 'Lagos Island',
42
+ 'Mushin', 'Lagos Mainland', 'Ojo', 'Oshodi-Isolo',
43
+ 'Shomolu', 'Surulere Lagos State']
44
+ })
45
+ end
46
+ end
47
+ end
48
+
49
+ describe '.capital' do
50
+ context 'when state is not found' do
51
+ it 'returns status with message' do
52
+ expect(state.details('AbIja')).to eq({message: "No state found for 'abija'", status: 404})
53
+ end
54
+ end
55
+
56
+ context 'when state is found' do
57
+ it 'returns the capital of a state' do
58
+ expect(state.capital('Plateau')).to eq('Jos')
59
+ end
25
60
  end
26
61
  end
27
62
  end
@@ -0,0 +1,142 @@
1
+ [
2
+ {
3
+ "state":"Akwa Ibom",
4
+ "alias":"akwa_ibom",
5
+ "cities":["Eket", "Ikot Ekpene", "Oron", "Uyo"]
6
+ },
7
+ {
8
+ "state":"Bauchi",
9
+ "alias":"bauchi",
10
+ "cities":["Bauchi"]
11
+ },
12
+ {
13
+ "state":"Benue",
14
+ "alias":"benue",
15
+ "cities":["Makurdi"]
16
+ },
17
+ {
18
+ "state":"Borno",
19
+ "alias":"borno",
20
+ "cities":["Bama", "Maiduguri"]
21
+ },
22
+ {
23
+ "state":"Bayelsa",
24
+ "alias":"bayelsa",
25
+ "cities":["Yenagoa"]
26
+ },
27
+ {
28
+ "state":"Delta",
29
+ "alias":"delta",
30
+ "cities":["Sapele"]
31
+ },
32
+ {
33
+ "state":"Ebonyi",
34
+ "alias":"ebonyi",
35
+ "cities":["Abakaliki"]
36
+ },
37
+ {
38
+ "state":"Ekiti",
39
+ "alias":"ekiti",
40
+ "cities":["Ado Ekiti"]
41
+ },
42
+ {
43
+ "state":"Enugu",
44
+ "alias":"enugu",
45
+ "cities":["Enugu", "Nsukka", "Agbani", "Awgu", "Udi", "Oji-River"]
46
+ },
47
+ {
48
+ "state":"Gombe",
49
+ "alias":"gombe",
50
+ "cities":["Gombe"]
51
+ },
52
+ {
53
+ "state":"Jigawa",
54
+ "alias":"jigawa",
55
+ "cities":["Dutse"]
56
+ },
57
+ {
58
+ "state":"Imo",
59
+ "alias":"imo",
60
+ "cities":["Okigwe", "Orlu"]
61
+ },
62
+ {
63
+ "state":"Kaduna",
64
+ "alias":"kaduna",
65
+ "cities":["Kaduna", "Zaria"]
66
+ },
67
+ {
68
+ "state":"Kebbi",
69
+ "alias":"kebbi",
70
+ "cities":["Birnin Kebbi"]
71
+ },
72
+ {
73
+ "state":"Kogi",
74
+ "alias":"kogi",
75
+ "cities":["Lokoja", "Okene"]
76
+ },
77
+ {
78
+ "state":"Lagos",
79
+ "alias":"lagos",
80
+ "cities":["Agege", "Ikeja"]
81
+ },
82
+ {
83
+ "state":"Katsina",
84
+ "alias":"katsina",
85
+ "cities":["Funtua", "Katsina"]
86
+ },
87
+ {
88
+ "state":"Kwara",
89
+ "alias":"kwara",
90
+ "cities":["Offa", "Ilorin"]
91
+ },
92
+ {
93
+ "state":"Nasarawa",
94
+ "alias":"nasarawa",
95
+ "cities":["Lafia"]
96
+ },
97
+ {
98
+ "state":"Niger",
99
+ "alias":"niger",
100
+ "cities":["Bida", "Suleja"]
101
+ },
102
+ {
103
+ "state":"Ogun",
104
+ "alias":"ogun",
105
+ "cities":["Ijebu Ode", "Shagamu"]
106
+ },
107
+ {
108
+ "state":"Ondo",
109
+ "alias":"ondo",
110
+ "cities":["Owo"]
111
+ },
112
+ {
113
+ "state":"Rivers",
114
+ "alias":"rivers",
115
+ "cities":["Port Harcourt"]
116
+ },
117
+ {
118
+ "state":"Oyo",
119
+ "alias":"oyo",
120
+ "cities":["Oyo"]
121
+ },
122
+ {
123
+ "state":"Osun",
124
+ "alias":"osun",
125
+ "cities":["Iwo", "Osogbo"]
126
+ },
127
+ {
128
+ "state":"Taraba",
129
+ "alias":"taraba",
130
+ "cities":["Wukari"]
131
+ },
132
+ {
133
+ "state":"Yobe",
134
+ "alias":"yobe",
135
+ "cities":["Nguru", "Potiskum"]
136
+ },
137
+ {
138
+ "state":"Zamfara",
139
+ "alias":"zamfara",
140
+ "cities":["Gusau"]
141
+ }
142
+ ]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: locations_ng
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fiyin Adebayo
@@ -45,13 +45,18 @@ extensions: []
45
45
  extra_rdoc_files: []
46
46
  files:
47
47
  - lib/locations_ng.rb
48
+ - lib/locations_ng/city.rb
49
+ - lib/locations_ng/lga.rb
48
50
  - lib/locations_ng/locations/cities.yml
49
51
  - lib/locations_ng/locations/lgas.yml
50
52
  - lib/locations_ng/locations/states.yml
51
53
  - lib/locations_ng/state.rb
52
54
  - lib/locations_ng/version.rb
55
+ - spec/locations_ng/city_spec.rb
56
+ - spec/locations_ng/lga_spec.rb
53
57
  - spec/locations_ng/state_spec.rb
54
58
  - spec/responses/canonical_states.json
59
+ - spec/responses/cities.json
55
60
  - spec/spec_helper.rb
56
61
  homepage: https://github.com/ceemion/locations_ng
57
62
  licenses:
@@ -78,6 +83,9 @@ signing_key:
78
83
  specification_version: 4
79
84
  summary: States, Cities and LGAs in Nigeria.
80
85
  test_files:
86
+ - spec/locations_ng/city_spec.rb
87
+ - spec/locations_ng/lga_spec.rb
81
88
  - spec/locations_ng/state_spec.rb
82
89
  - spec/responses/canonical_states.json
90
+ - spec/responses/cities.json
83
91
  - spec/spec_helper.rb