Class: LocationsNg::Lga

Inherits:
Object
  • Object
show all
Defined in:
lib/locations_ng/lga.rb

Class Method Summary collapse

Class Method Details

.allObject



6
7
8
# File 'lib/locations_ng/lga.rb', line 6

def all
  @all_lgas
end

.lgas(state) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/locations_ng/lga.rb', line 10

def lgas(state)
  lga_index = @all_lgas.index{ |l| l['state_alias'] == format_query(state) }

  unless lga_index.nil?
    return @all_lgas[lga_index]['lgas']
  end

  {message: "No lgas found for '#{state}'", status: 404}
end

.localities(state, lga) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/locations_ng/lga.rb', line 20

def localities(state, lga)
  return {message: 'You must enter a state and lga.', status: 500} unless state && lga

  state_index = @all_lgas.index{ |s| s['state_alias'] == format_query(state) }

  unless state_index
    return {message: "'#{state}' state not found.", status: 404}
  end

  lga_index = @all_lgas[state_index]['locality'].index{ |l| l['lga_alias'] == format_query(lga) }

  unless lga_index
    return {message: "'#{lga}' LGA not found for '#{state}' state.", status: 404}
  end

  @all_lgas[state_index]['locality'][lga_index]['localities']
end