Module: Cities

Defined in:
lib/cities.rb,
lib/cities/city.rb,
lib/cities/version.rb

Defined Under Namespace

Classes: City, DataNotFound

Constant Summary collapse

VERSION =
'0.3.1'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.data_pathObject

Returns the value of attribute data_path


7
8
9
# File 'lib/cities.rb', line 7

def data_path
  @data_path
end

Class Method Details

.cities_in_country(code) ⇒ Object


13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/cities.rb', line 13

def cities_in_country(code)
  if self.cities_in_country?(code)
    json = File.read(path_for_country(code))
    country_data = MultiJson.load(json)
    country_data.reduce({}) do |cities, city_data|
      cities[city_data.first] = City.new(city_data.last)
      cities
    end
  else
    {}
  end
end

.cities_in_country?(code) ⇒ Boolean

Returns:

  • (Boolean)

9
10
11
# File 'lib/cities.rb', line 9

def cities_in_country?(code)
  File.exist?(path_for_country(code))
end