Class: TopTen::CLI

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

Instance Method Summary collapse

Instance Method Details

#callObject



3
4
5
6
7
8
9
# File 'lib/top_ten/cli.rb', line 3

def call
    welcome
    TopTen::Scraper.scrape_country
    list_countries
    menu
    goodbye
end

#countriesObject



17
18
19
# File 'lib/top_ten/cli.rb', line 17

def countries
    @countries = TopTen::Top.all
end

#goodbyeObject



46
47
48
# File 'lib/top_ten/cli.rb', line 46

def goodbye
    puts "Safe travels! See you next time!"
end

#list_countriesObject



21
22
23
24
25
26
# File 'lib/top_ten/cli.rb', line 21

def list_countries
    puts "Here are Lonely Planet's Best in Travel Top 10 Countries to Visit in 2018:"
    countries.each do |country|
        puts "#{country.name}"
    end
end


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/top_ten/cli.rb', line 28

def menu
    puts "Enter the number of the country you would like to learn more about."
    puts "You can also enter 'list' to view the list again or 'exit' to exit the program."
    input = gets.strip.downcase

    if input != "exit"
        if input.to_i.between?(1,10)
            the_country = @countries[input.to_i - 1]
            puts "#{the_country.name} - #{the_country.description}"
        elsif input == "list"
            list_countries
        else
            puts "Not sure what you mean."
        end
    menu
    end
end

#welcomeObject



11
12
13
14
15
# File 'lib/top_ten/cli.rb', line 11

def welcome
    puts "Welcome, traveler!"
    puts "Not sure where you should go in 2018?"
    puts "This should help!"
end