class LocationsNg::State
Public Class Methods
all()
click to toggle source
# File lib/locations_ng/state.rb, line 6 def all @all_states.map{ |s| {name: s['name'], capital: s['capital']} } end
capital(state)
click to toggle source
# File lib/locations_ng/state.rb, line 23 def capital(state) state_index = @all_states.index{ |s| s['alias'] == format_query(state) } unless state_index.nil? return @all_states[state_index]['capital'] end {message: "No state found for '#{state}'", status: 404} end
details(state)
click to toggle source
# File lib/locations_ng/state.rb, line 10 def details(state) state_index = @all_states.index{ |s| s['alias'] == format_query(state) } if state_index.nil? {message: "No state found for '#{state}'", status: 404} else res = @all_states[state_index] res['cities'] = LocationsNg::City.cities(state) res['lgas'] = LocationsNg::Lga.lgas(state) res end end
Private Class Methods
format_query(query)
click to toggle source
# File lib/locations_ng/state.rb, line 35 def format_query(query) query ? query.downcase.tr(' ', '_') : query end