class Couchsurfing::Place

Place class handels on geographical data returned from Scraper class

Attributes

cities[RW]
city[RW]
continent[RW]
continents[RW]
countries[RW]
country[RW]
locations[RW]

Public Class Methods

new() click to toggle source
# File lib/couchsurfing/place.rb, line 6
def initialize
  @continents = []
  z = Couchsurfing::Scraper.new
  @locations = z.scrape_locations
  @locations.each { |location| @continents.sort! << location['continent'] }
end

Public Instance Methods

city_selection(num) click to toggle source
# File lib/couchsurfing/place.rb, line 42
def city_selection(num)
  i = num - 1
  @city = @cities[i]
end
continent_selection(num) click to toggle source
# File lib/couchsurfing/place.rb, line 13
def continent_selection(num)
  i = num - 1
  @continent = @continents[i]
  select_countries(@continent)
end
country_selection(num) click to toggle source
# File lib/couchsurfing/place.rb, line 29
def country_selection(num)
  i = num - 1
  @country = @countries[i]
  select_cities(@country)
end
select_cities(choice_c) click to toggle source
# File lib/couchsurfing/place.rb, line 35
def select_cities(choice_c)
  hash = @hash[0]['provinces']
  hash.select { |c| @cities = c['cities'] if c['country'] == choice_c }

  @cities = @cities.sample(5).sort!
end
select_countries(choice_c) click to toggle source
# File lib/couchsurfing/place.rb, line 19
def select_countries(choice_c)
  @countries = []

  @hash = @locations.select { |location| location['continent'] == choice_c }

  @hash[0]['provinces'].each { |hash| @countries << hash['country'] }

  @countries = @countries.sample(5).sort!
end