Class: LocationsNg::City

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

Class Method Summary collapse

Class Method Details

.allObject



3
4
5
# File 'lib/locations_ng/city.rb', line 3

def self.all
  load_cities
end

.cities(state) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/locations_ng/city.rb', line 7

def self.cities(state)
  state = state.downcase.gsub(' ', '_')
  all_cities = load_cities

  city_index = all_cities.index{|c| c['alias'] == state}

  if city_index.nil?
    {message: "No cities found for '#{state}'", status: 404}
  else
    all_cities[city_index]['cities']
  end
end