locations_ng 1.0.1 → 1.0.2
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.
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa049b1575ec78e58249287f6d569e18f89d4142
|
4
|
+
data.tar.gz: b5cf8f333940cef919906c7d58a04a04233e45f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab36708ef06d4666f7f2e3eae7534454c5ce2b03fbbea09da34e55e36071a5888a1b7b26ea4ca5605ae2cf59f6bae09724677e45103bf59a32881134bafe5b71
|
7
|
+
data.tar.gz: d96f563f5709afb642b657595f6f8bfcf5d569bd8021c2c9eb97ec556eb9526d946f8a6a060ac3996781355cd13d7b73a89bb2411c535db3fab0bc0ff917e750
|
data/lib/locations_ng/city.rb
CHANGED
@@ -1,34 +1,36 @@
|
|
1
1
|
module LocationsNg
|
2
2
|
class City
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
class << self
|
4
|
+
def all
|
5
|
+
load_cities
|
6
|
+
end
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
def cities(state)
|
9
|
+
state_query = state.downcase.gsub(' ', '_')
|
10
|
+
all_cities = load_cities
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
if state_query == 'federal_capital_territory'
|
13
|
+
state_query = 'fct'
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
+
city_index = all_cities.index{|c| c['alias'] == state_query}
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
if city_index.nil?
|
19
|
+
{message: "No cities found for '#{state}'", status: 404}
|
20
|
+
else
|
21
|
+
all_cities[city_index]['cities']
|
22
|
+
end
|
21
23
|
end
|
22
|
-
end
|
23
24
|
|
24
|
-
|
25
|
+
private
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
def load_cities
|
28
|
+
YAML.load(File.read(files_location 'cities'))
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
31
|
+
def files_location(file)
|
32
|
+
File.expand_path("../locations/#{file}.yml", __FILE__)
|
33
|
+
end
|
32
34
|
end
|
33
35
|
end
|
34
36
|
end
|
data/lib/locations_ng/lga.rb
CHANGED
@@ -1,30 +1,58 @@
|
|
1
1
|
module LocationsNg
|
2
2
|
class Lga
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
class << self
|
4
|
+
def all
|
5
|
+
load_lgas
|
6
|
+
end
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
def lgas(state)
|
9
|
+
query = format_query(state)
|
10
|
+
all_lgas = load_lgas
|
10
11
|
|
11
|
-
|
12
|
+
lga_index = all_lgas.index{|l| l['state_alias'] == query}
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
if lga_index.nil?
|
15
|
+
{message: "No lgas found for '#{state}'", status: 404}
|
16
|
+
else
|
17
|
+
all_lgas[lga_index]['lgas']
|
18
|
+
end
|
17
19
|
end
|
18
|
-
end
|
19
20
|
|
20
|
-
|
21
|
+
def localities(state, lga)
|
22
|
+
return {message: 'You must enter a state and lga.', status: 500} unless state && lga
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
|
24
|
+
state_query = format_query(state)
|
25
|
+
lga_query = format_query(lga)
|
26
|
+
all_lgas = load_lgas
|
27
|
+
|
28
|
+
state_index = all_lgas.index{|s| s['state_alias'] == state_query}
|
29
|
+
|
30
|
+
if state_index
|
31
|
+
lga_index = all_lgas[state_index]['locality'].index{|l| l['lga_alias'] == lga_query}
|
32
|
+
|
33
|
+
if lga_index
|
34
|
+
all_lgas[state_index]['locality'][lga_index]['localities']
|
35
|
+
else
|
36
|
+
{message: "'#{lga}' LGA not found for '#{state}' state.", status: 404}
|
37
|
+
end
|
38
|
+
else
|
39
|
+
{message: "'#{state}' state not found.", status: 404}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def load_lgas
|
46
|
+
YAML.load(File.read(files_location 'lgas'))
|
47
|
+
end
|
25
48
|
|
26
|
-
|
27
|
-
|
49
|
+
def files_location(file)
|
50
|
+
File.expand_path("../locations/#{file}.yml", __FILE__)
|
51
|
+
end
|
52
|
+
|
53
|
+
def format_query(query)
|
54
|
+
query ? query.downcase.gsub(' ', '_') : query
|
55
|
+
end
|
28
56
|
end
|
29
57
|
end
|
30
58
|
end
|