Class: LocationsNg::State
- Inherits:
-
Object
- Object
- LocationsNg::State
- Defined in:
- lib/locations_ng/state.rb
Class Method Summary collapse
Class Method Details
.all ⇒ Object
3 4 5 |
# File 'lib/locations_ng/state.rb', line 3 def self.all load_states.map{ |s| {name: s['name'], capital: s['capital']} } end |
.capital(state) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/locations_ng/state.rb', line 23 def self.capital(state) state = state.downcase.gsub(' ', '_') all_states = load_states state_index = all_states.index{|s| s['alias'] == state} if state_index.nil? {message: "No state found for '#{state}'", status: 404} else all_states[state_index]['capital'] end end |
.details(state) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/locations_ng/state.rb', line 7 def self.details(state) state = state.downcase.gsub(' ', '_') all_states = load_states state_index = all_states.index{|s| s['alias'] == state} if state_index.nil? {message: "No state found for '#{state}'", status: 404} else res = all_states[state_index].with_indifferent_access res['cities'] = LocationsNg::City.cities(state) res['lgas'] = LocationsNg::Lga.lgas(state) res end end |