Module: WorldVoyager

Defined in:
lib/world_voyager.rb,
lib/world_voyager/version.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

DATABASE_PATH =
'lib/db/worldcities.csv'
VERSION =
'0.1.0'

Class Method Summary collapse

Class Method Details

.cities(district) ⇒ Object



36
37
38
39
40
41
# File 'lib/world_voyager.rb', line 36

def cities(district)
  install if @data.empty?

  district_downcased = district.downcase
  @data.select { |d| d[:district].downcase == district_downcased }.map { |d| d[:city] }.uniq.sort
end

.countriesObject



23
24
25
26
27
# File 'lib/world_voyager.rb', line 23

def countries
  install if @data.empty?

  @data.map { |d| d[:country] }.uniq.sort
end

.districts(country) ⇒ Object



29
30
31
32
33
34
# File 'lib/world_voyager.rb', line 29

def districts(country)
  install if @data.empty?

  country_downcased = country.downcase
  @data.select { |d| d[:country].downcase == country_downcased }.map { |d| d[:district] }.uniq.sort
end

.installObject



15
16
17
18
19
20
21
# File 'lib/world_voyager.rb', line 15

def install
  require 'csv'

  CSV.foreach(DATABASE_PATH, headers: true, header_converters: :symbol) do |row|
    @data << row.to_h
  end
end