Class: TopTravelDestinations::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/top_travel_destinations/cli.rb

Instance Method Summary collapse

Instance Method Details

#add_attributes_to_destination(destination) ⇒ Object



13
14
15
16
# File 'lib/top_travel_destinations/cli.rb', line 13

def add_attributes_to_destination(destination)
    attributes = TopTravelDestinations::Scraper.scrape_destination_page(destination.destination_url)
    destination.add_attributes(attributes)
end

#callObject



3
4
5
6
7
# File 'lib/top_travel_destinations/cli.rb', line 3

def call
    create_list
    list_destinations
    menu
end

#create_listObject



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

def create_list
    TopTravelDestinations::Scraper.scrape_main_page('https://www.tripadvisor.com/TravelersChoice-Destinations-cTop-g1')
end

#destination_details(destination) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/top_travel_destinations/cli.rb', line 48

def destination_details(destination)
    puts "\n#{destination.location}\n"
    puts "\nWhy visit?"
    puts "\n#{destination.description}"
    puts "http://www.visitgreece.gr/en/greek_islands/crete" if destination.description.nil?
    puts "\nDon't miss:" unless destination.attractions == []
    destination.attractions.each.with_index(1) {|attraction, i| puts "    #{i}. #{attraction}"}
    puts "\nCurrent lowest airfare: #{destination.flight_price}" unless destination.flight_price == nil
    if destination.weather_high != ""
        puts "\nCurrent local weather:"
        puts "   High: #{destination.weather_high.match(/[^°]*/)}°"
        puts "   Low: #{destination.weather_low.match(/[^°]*/)}°"
    end
end

#list_by_continentObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/top_travel_destinations/cli.rb', line 63

def list_by_continent
    puts "\nAfrica, Asia, Europe, North America, South America, or Oceania?"
    continent_input = gets.strip

        puts "\n#{continent_input.split(" ").map {|word| word.capitalize}.join(" ")
}"
        puts "----------------------------------"
        destinations = TopTravelDestinations::Destination.find_by_continent(continent_input)
        destinations.each do |destination| 
            puts "#{TopTravelDestinations::Destination.all.find_index(destination) + 1}. #{destination.location}"
        end
        puts "----------------------------------"
        puts "*Technically, the Society Islands are not associated with a continent, but with the region of Oceania." if continent_input.downcase == "oceania"
end

#list_destinationsObject



18
19
20
21
22
# File 'lib/top_travel_destinations/cli.rb', line 18

def list_destinations
    puts "\nTop Travel Destinations"
    puts "-----------------------"
    TopTravelDestinations::Destination.all.each.with_index(1) {|destination, i| puts "#{i}. #{destination.location}"}
end


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/top_travel_destinations/cli.rb', line 24

def menu
    input = ""
    while input != "exit"
        puts "\nEnter the number of the destination you'd like to know more about, type list for the original list, type display to display by continent, or exit:"
        input = gets.strip.downcase
        
        if input.to_i.between?(1, 25)
            destination = TopTravelDestinations::Destination.all[input.to_i - 1]
            add_attributes_to_destination(destination)
            destination_details(destination)
        elsif input == "display"
            list_by_continent
        elsif input == "list"
            list_destinations
        elsif input == "exit"
            puts "\nThanks for using Top Travel Destinations! Safe travels.\n"
            break
        else
            puts "\nNot sure what you mean.\n"
            menu
        end 
    end
end