locations_ng 1.0.2 → 1.0.3
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.rb +1 -0
- data/lib/locations_ng/city.rb +10 -18
- data/lib/locations_ng/lga.rb +18 -31
- data/lib/locations_ng/load_file.rb +13 -0
- data/lib/locations_ng/state.rb +11 -23
- data/lib/locations_ng/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cdfcb7c01c3a323698dcbd29ca166dd6444d7fde
|
4
|
+
data.tar.gz: f32b8b96950a4cb8fb307832be130888f769eb01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad89e4edd1f6e9d0cee7bdc7c978fef02c8b202b2b0e7bf9ca6ff275c7d5dcda54479a21af9e56cdf1b8ca0c07e67fa924efa7a4dd8c1fd31573c6ee8f97e1d8
|
7
|
+
data.tar.gz: a0ddc4f9be213ad0b8a3e45f908cfeb4d046f4bdae101415bb16ae25f88539e6a91b5363200a554bf1abb73931bfd466a626192adae20f9217d31b8f852a3bb7
|
data/lib/locations_ng.rb
CHANGED
data/lib/locations_ng/city.rb
CHANGED
@@ -1,35 +1,27 @@
|
|
1
1
|
module LocationsNg
|
2
2
|
class City
|
3
|
+
@all_cities = LoadFile.read('cities')
|
4
|
+
|
3
5
|
class << self
|
4
6
|
def all
|
5
|
-
|
7
|
+
@all_cities
|
6
8
|
end
|
7
9
|
|
8
10
|
def cities(state)
|
9
|
-
state_query = state.downcase.
|
10
|
-
|
11
|
+
state_query = state_query(state.downcase.tr(' ', '_'))
|
12
|
+
city_index = @all_cities.index{ |c| c['alias'] == state_query }
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
+
unless city_index.nil?
|
15
|
+
return @all_cities[city_index]['cities']
|
14
16
|
end
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
if city_index.nil?
|
19
|
-
{message: "No cities found for '#{state}'", status: 404}
|
20
|
-
else
|
21
|
-
all_cities[city_index]['cities']
|
22
|
-
end
|
18
|
+
{message: "No cities found for '#{state}'", status: 404}
|
23
19
|
end
|
24
20
|
|
25
21
|
private
|
26
22
|
|
27
|
-
def
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
def files_location(file)
|
32
|
-
File.expand_path("../locations/#{file}.yml", __FILE__)
|
23
|
+
def state_query(state)
|
24
|
+
state == 'federal_capital_territory' ? 'fct' : state
|
33
25
|
end
|
34
26
|
end
|
35
27
|
end
|
data/lib/locations_ng/lga.rb
CHANGED
@@ -1,57 +1,44 @@
|
|
1
1
|
module LocationsNg
|
2
2
|
class Lga
|
3
|
+
@all_lgas = LoadFile.read('lgas')
|
4
|
+
|
3
5
|
class << self
|
4
6
|
def all
|
5
|
-
|
7
|
+
@all_lgas
|
6
8
|
end
|
7
9
|
|
8
10
|
def lgas(state)
|
9
|
-
|
10
|
-
all_lgas = load_lgas
|
11
|
-
|
12
|
-
lga_index = all_lgas.index{|l| l['state_alias'] == query}
|
11
|
+
lga_index = @all_lgas.index{ |l| l['state_alias'] == format_query(state) }
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
else
|
17
|
-
all_lgas[lga_index]['lgas']
|
13
|
+
unless lga_index.nil?
|
14
|
+
return @all_lgas[lga_index]['lgas']
|
18
15
|
end
|
16
|
+
|
17
|
+
{message: "No lgas found for '#{state}'", status: 404}
|
19
18
|
end
|
20
19
|
|
21
20
|
def localities(state, lga)
|
22
21
|
return {message: 'You must enter a state and lga.', status: 500} unless state && lga
|
23
22
|
|
24
|
-
|
25
|
-
lga_query = format_query(lga)
|
26
|
-
all_lgas = load_lgas
|
23
|
+
state_index = @all_lgas.index{ |s| s['state_alias'] == format_query(state) }
|
27
24
|
|
28
|
-
state_index
|
25
|
+
unless state_index
|
26
|
+
return {message: "'#{state}' state not found.", status: 404}
|
27
|
+
end
|
29
28
|
|
30
|
-
|
31
|
-
lga_index = all_lgas[state_index]['locality'].index{|l| l['lga_alias'] == lga_query}
|
29
|
+
lga_index = @all_lgas[state_index]['locality'].index{ |l| l['lga_alias'] == format_query(lga) }
|
32
30
|
|
33
|
-
|
34
|
-
|
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}
|
31
|
+
unless lga_index
|
32
|
+
return {message: "'#{lga}' LGA not found for '#{state}' state.", status: 404}
|
40
33
|
end
|
41
|
-
end
|
42
34
|
|
43
|
-
|
44
|
-
|
45
|
-
def load_lgas
|
46
|
-
YAML.load(File.read(files_location 'lgas'))
|
35
|
+
@all_lgas[state_index]['locality'][lga_index]['localities']
|
47
36
|
end
|
48
37
|
|
49
|
-
|
50
|
-
File.expand_path("../locations/#{file}.yml", __FILE__)
|
51
|
-
end
|
38
|
+
private
|
52
39
|
|
53
40
|
def format_query(query)
|
54
|
-
query ? query.downcase.
|
41
|
+
query ? query.downcase.tr(' ', '_') : query
|
55
42
|
end
|
56
43
|
end
|
57
44
|
end
|
data/lib/locations_ng/state.rb
CHANGED
@@ -1,20 +1,19 @@
|
|
1
1
|
module LocationsNg
|
2
2
|
class State
|
3
|
+
@all_states = LocationsNg::LoadFile.read('states')
|
4
|
+
|
3
5
|
class << self
|
4
6
|
def all
|
5
|
-
|
7
|
+
@all_states.map{ |s| {name: s['name'], capital: s['capital']} }
|
6
8
|
end
|
7
9
|
|
8
10
|
def details(state)
|
9
|
-
|
10
|
-
all_states = load_states
|
11
|
-
|
12
|
-
state_index = all_states.index{|s| s['alias'] == state_query}
|
11
|
+
state_index = @all_states.index{ |s| s['alias'] == format_query(state) }
|
13
12
|
|
14
13
|
if state_index.nil?
|
15
14
|
{message: "No state found for '#{state}'", status: 404}
|
16
15
|
else
|
17
|
-
res = all_states[state_index].with_indifferent_access
|
16
|
+
res = @all_states[state_index].with_indifferent_access
|
18
17
|
res['cities'] = LocationsNg::City.cities(state)
|
19
18
|
res['lgas'] = LocationsNg::Lga.lgas(state)
|
20
19
|
res
|
@@ -22,30 +21,19 @@ module LocationsNg
|
|
22
21
|
end
|
23
22
|
|
24
23
|
def capital(state)
|
25
|
-
|
26
|
-
all_states = load_states
|
27
|
-
|
28
|
-
state_index = all_states.index{|s| s['alias'] == state_query}
|
24
|
+
state_index = @all_states.index{ |s| s['alias'] == format_query(state) }
|
29
25
|
|
30
|
-
|
31
|
-
|
32
|
-
else
|
33
|
-
all_states[state_index]['capital']
|
26
|
+
unless state_index.nil?
|
27
|
+
return @all_states[state_index]['capital']
|
34
28
|
end
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
29
|
|
39
|
-
|
40
|
-
YAML.load(File.read(files_location 'states'))
|
30
|
+
{message: "No state found for '#{state}'", status: 404}
|
41
31
|
end
|
42
32
|
|
43
|
-
|
44
|
-
File.expand_path("../locations/#{file}.yml", __FILE__)
|
45
|
-
end
|
33
|
+
private
|
46
34
|
|
47
35
|
def format_query(query)
|
48
|
-
query ? query.downcase.
|
36
|
+
query ? query.downcase.tr(' ', '_') : query
|
49
37
|
end
|
50
38
|
end
|
51
39
|
end
|
data/lib/locations_ng/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: locations_ng
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fiyin Adebayo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -47,6 +47,7 @@ files:
|
|
47
47
|
- lib/locations_ng.rb
|
48
48
|
- lib/locations_ng/city.rb
|
49
49
|
- lib/locations_ng/lga.rb
|
50
|
+
- lib/locations_ng/load_file.rb
|
50
51
|
- lib/locations_ng/locations/cities.yml
|
51
52
|
- lib/locations_ng/locations/lgas.yml
|
52
53
|
- lib/locations_ng/locations/states.yml
|