Module: WorldWrap

Defined in:
lib/world_wrap.rb

Instance Method Summary collapse

Instance Method Details

#cities(options = {}) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/world_wrap.rb', line 17

def cities options = {}
  return "Please pass a state name or code" if options[:state].nil? || options[:state].empty?
  state = options[:state].downcase
#    return "not a valid key" if is_invalid_key?(STATES, state) TODO
  return "Need to store data for #{state} Or its not a state in the given list" unless CITIES.has_key?(state)
  CITIES[state]
end

#countries(options = {}) ⇒ Object



5
6
7
# File 'lib/world_wrap.rb', line 5

def countries options = {}
  COUNTRIES
end

#is_invalid_key?(objects, value) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/world_wrap.rb', line 25

def is_invalid_key?(objects, value)
  is_valid = objects.select{|object| object if [object[:name].downcase, object[:code].downcase].include?(value)}
  is_valid.empty?
end

#states(options = {}) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/world_wrap.rb', line 9

def states options = {}
  return "Please pass a country name or code" if options[:country].nil? || options[:country].empty?
  country = options[:country].downcase
  return "not a valid key" if is_invalid_key?(COUNTRIES, country)
  return "Need to save data for #{country}" unless STATES.has_key?(country)
  STATES[country]
end