locations_ng 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/locations_ng/city.rb +23 -21
- data/lib/locations_ng/lga.rb +46 -18
- data/lib/locations_ng/locations/lgas.yml +12500 -486
- data/lib/locations_ng/state.rb +36 -30
- data/lib/locations_ng/version.rb +1 -1
- data/spec/locations_ng/city_spec.rb +1 -1
- data/spec/locations_ng/lga_spec.rb +45 -7
- data/spec/locations_ng/state_spec.rb +7 -7
- data/spec/responses/lgas.json +14947 -574
- metadata +2 -2
data/lib/locations_ng/state.rb
CHANGED
@@ -1,46 +1,52 @@
|
|
1
1
|
module LocationsNg
|
2
2
|
class State
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
class << self
|
4
|
+
def all
|
5
|
+
load_states.map{ |s| {name: s['name'], capital: s['capital']} }
|
6
|
+
end
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
def details(state)
|
9
|
+
state_query = format_query(state)
|
10
|
+
all_states = load_states
|
10
11
|
|
11
|
-
|
12
|
+
state_index = all_states.index{|s| s['alias'] == state_query}
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
if state_index.nil?
|
15
|
+
{message: "No state found for '#{state}'", status: 404}
|
16
|
+
else
|
17
|
+
res = all_states[state_index].with_indifferent_access
|
18
|
+
res['cities'] = LocationsNg::City.cities(state)
|
19
|
+
res['lgas'] = LocationsNg::Lga.lgas(state)
|
20
|
+
res
|
21
|
+
end
|
20
22
|
end
|
21
|
-
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
24
|
+
def capital(state)
|
25
|
+
state_query = format_query(state)
|
26
|
+
all_states = load_states
|
26
27
|
|
27
|
-
|
28
|
+
state_index = all_states.index{|s| s['alias'] == state_query}
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
if state_index.nil?
|
31
|
+
{message: "No state found for '#{state}'", status: 404}
|
32
|
+
else
|
33
|
+
all_states[state_index]['capital']
|
34
|
+
end
|
33
35
|
end
|
34
|
-
end
|
35
36
|
|
36
|
-
|
37
|
+
private
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
39
|
+
def load_states
|
40
|
+
YAML.load(File.read(files_location 'states'))
|
41
|
+
end
|
42
|
+
|
43
|
+
def files_location(file)
|
44
|
+
File.expand_path("../locations/#{file}.yml", __FILE__)
|
45
|
+
end
|
41
46
|
|
42
|
-
|
43
|
-
|
47
|
+
def format_query(query)
|
48
|
+
query ? query.downcase.gsub(' ', '_') : query
|
49
|
+
end
|
44
50
|
end
|
45
51
|
end
|
46
52
|
end
|
data/lib/locations_ng/version.rb
CHANGED
@@ -15,7 +15,7 @@ module LocationsNg
|
|
15
15
|
describe '.cities' do
|
16
16
|
context 'when state is not found' do
|
17
17
|
it 'returns error message' do
|
18
|
-
expect(city.cities('Invalid State')).to eq({message: "No cities found for '
|
18
|
+
expect(city.cities('Invalid State')).to eq({message: "No cities found for 'Invalid State'", status: 404})
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -15,18 +15,56 @@ module LocationsNg
|
|
15
15
|
describe '.lgas' do
|
16
16
|
context 'when lgas for a state is not found' do
|
17
17
|
it 'returns an error message' do
|
18
|
-
expect(lga.lgas('Unknown State')).to eq({message: "No lgas found for '
|
18
|
+
expect(lga.lgas('Unknown State')).to eq({message: "No lgas found for 'Unknown State'", status: 404})
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
context 'when state is found' do
|
23
23
|
it 'returns the lgas for state' do
|
24
|
-
expect(lga.lgas('
|
25
|
-
|
26
|
-
'
|
27
|
-
'Ikeja', 'Ikorodu', 'Kosofe', 'Lagos Island',
|
28
|
-
'Mushin', '
|
29
|
-
|
24
|
+
expect(lga.lgas('lagos').count).to eq(20)
|
25
|
+
expect(lga.lgas('Lagos')).to eq(['Agege', 'Ajeromi/ifelodun', 'Alimosho', 'Amuwo-odofin', 'Apapa',
|
26
|
+
'Badagry', 'Epe', 'Eti-osa', 'Ibeju/lekki', 'Ifako/ijaiye',
|
27
|
+
'Ikeja', 'Ikorodu', 'Kosofe', 'Lagos Island', 'Lagos Mainland',
|
28
|
+
'Mushin', 'Ojo', 'Oshodi/isolo', 'Shomolu', 'Surulere'
|
29
|
+
])
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '.localities' do
|
35
|
+
context 'when no query is passed' do
|
36
|
+
it 'returns 500' do
|
37
|
+
expect(lga.localities(nil, nil)).to eq({message: 'You must enter a state and lga.', status: 500})
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'returns 500' do
|
41
|
+
expect(lga.localities('Kano', nil)).to eq({message: 'You must enter a state and lga.', status: 500})
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'returns 500' do
|
45
|
+
expect(lga.localities(nil, 'Aba South')).to eq({message: 'You must enter a state and lga.', status: 500})
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'when state is not found' do
|
50
|
+
it 'returns an error message' do
|
51
|
+
expect(lga.localities('logos', 'South West')).to eq({message: "'logos' state not found.", status: 404})
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'when lgas for a state is not found' do
|
56
|
+
it 'returns an error message' do
|
57
|
+
expect(lga.localities('Abia', 'Isiala Ngwa')).to eq({message: "'Isiala Ngwa' LGA not found for 'Abia' state.", status: 404})
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'when localities are found for lga' do
|
62
|
+
it 'returns localities for LGAs in a state' do
|
63
|
+
expect(lga.localities('Abia', 'Aba North')).to eq(['Ariaria', 'Asaokpoja', 'Asaokpulor',
|
64
|
+
'Eziama ward', 'Industrial', 'Ogbor 1',
|
65
|
+
'Ogbor 2', 'Old GRA', 'Osusu 1', 'Osusu 2',
|
66
|
+
'St. Eugene', 'Umuogor', 'Umuola', 'Uratta'
|
67
|
+
])
|
30
68
|
end
|
31
69
|
end
|
32
70
|
end
|
@@ -19,7 +19,7 @@ module LocationsNg
|
|
19
19
|
describe '.details' do
|
20
20
|
context 'when state is not found' do
|
21
21
|
it 'returns status with message' do
|
22
|
-
expect(state.details('AbIja')).to eq({message: "No state found for '
|
22
|
+
expect(state.details('AbIja')).to eq({message: "No state found for 'AbIja'", status: 404})
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -35,12 +35,12 @@ module LocationsNg
|
|
35
35
|
'maxLong'=>3.696727799999999,
|
36
36
|
'alias'=>'lagos',
|
37
37
|
'cities'=>%w(Agege Ikeja),
|
38
|
-
'lgas'=>['Agege', 'Ajeromi
|
39
|
-
'Amuwo-
|
40
|
-
'Eti
|
38
|
+
'lgas'=>['Agege', 'Ajeromi/ifelodun', 'Alimosho',
|
39
|
+
'Amuwo-odofin', 'Apapa', 'Badagry', 'Epe',
|
40
|
+
'Eti-osa', 'Ibeju/lekki', 'Ifako/ijaiye',
|
41
41
|
'Ikeja', 'Ikorodu', 'Kosofe', 'Lagos Island',
|
42
|
-
'
|
43
|
-
'Shomolu', 'Surulere
|
42
|
+
'Lagos Mainland', 'Mushin', 'Ojo', 'Oshodi/isolo',
|
43
|
+
'Shomolu', 'Surulere']
|
44
44
|
})
|
45
45
|
end
|
46
46
|
end
|
@@ -49,7 +49,7 @@ module LocationsNg
|
|
49
49
|
describe '.capital' do
|
50
50
|
context 'when state is not found' do
|
51
51
|
it 'returns status with message' do
|
52
|
-
expect(state.details('AbIja')).to eq({message: "No state found for '
|
52
|
+
expect(state.details('AbIja')).to eq({message: "No state found for 'AbIja'", status: 404})
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|