Class: TravelLeisure::CLI

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

Overview

code handling CLI display logic and user input

Instance Method Summary collapse

Instance Method Details

#alt_menuObject



89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/travel_leisure/cli.rb', line 89

def alt_menu
  puts "\nWould you like to see another travel guide? Type 'Yes' or 'Y' ".yellow.bold
  puts "\nWould you like to exit? Type 'E' or 'Exit' ".yellow.bold
  input = gets.strip.downcase
  if input == 'yes' || input == 'y'
    menu_helper
  elsif input == 'exit' || input == 'e'
    good_bye
  else
    puts "Sorry, I didn't understand that input.".red.bold
    alt_menu
  end
end

#good_byeObject



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

def good_bye
  puts "Thank you for checking out Command Line Travel Guides!".yellow.bold
  exit!
end

#greetingObject



10
11
12
13
14
# File 'lib/travel_leisure/cli.rb', line 10

def greeting
  puts "\nWelcome to Command Line Travel Guides!".blue.bold
  puts "Would you like to see our list of destinations?".yellow
  puts "If so, please type 'Yes' or 'Y'!".yellow
end

#list_destinationsObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/travel_leisure/cli.rb', line 40

def list_destinations
    TravelLeisure::Destination.all.each.with_index(1) do |destination, index|
          puts "#{index}. #{destination.city}, #{destination.country}"
  end

  def select_destination
    puts "\nPlease enter the number of the travel guide you would like to access:".yellow.bold
      input = gets.strip
      destination = TravelLeisure::Destination.find(input.to_i)
      if input == "exit" || input == "e"
        good_bye
      elsif input.to_i.between?(1,TravelLeisure::Destination.all.length)
        print_destination(destination)
      else
        puts "Sorry! I didn't understand that input, please try again".red.bold
        select_destination
      end
  end

  def print_destination(destination)
    puts ""
    puts "----------- #{destination.city}, #{destination.country} -----------".blue.bold
    puts ""
    puts "Best Time To Visit: #{destination.best_time_to_visit}".green.bold
    puts "\nTransportation: #{destination.transportation}".green.bold
    puts "\nWeather: #{destination.weather}".green.bold
    puts "\nKnow Before Visiting: #{destination.know_before_visiting}".green.bold
    puts "\nLanguage: #{destination.language}".green.bold
    puts "\nCurrency: #{destination.currency}".green.bold
    puts "\nWould you like to read more on #{destination.city}? Please enter 'Y' or 'N'".yellow.bold
      input = gets.strip.downcase
      case input
      when 'y' || 'yes'
        puts ""
        puts "More info:".yellow
        puts ""
        puts destination.description
        alt_menu
      when 'n' || 'no'
        alt_menu
      when 'exit'
        good_bye
      else
        puts ""
        puts "Sorry, I didn't understand that input.".red.bold
        alt_menu
      end
  end

  def alt_menu
    puts "\nWould you like to see another travel guide? Type 'Yes' or 'Y' ".yellow.bold
    puts "\nWould you like to exit? Type 'E' or 'Exit' ".yellow.bold
    input = gets.strip.downcase
    if input == 'yes' || input == 'y'
      menu_helper
    elsif input == 'exit' || input == 'e'
      good_bye
    else
      puts "Sorry, I didn't understand that input.".red.bold
      alt_menu
    end
  end

  
end


21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/travel_leisure/cli.rb', line 21

def menu 
    input = gets.strip.downcase
    if input == "yes" || input == "y"
      menu_helper
    elsif input == "exit" || input == "e"
      good_bye         
    else
      puts "Sorry! I didn't understand that input, please try again".red.bold
      puts "Would you like to see our list?".yellow
      puts "If so, please type 'Yes' or 'Y' or exit.".yellow
      menu 
    end
end


35
36
37
38
# File 'lib/travel_leisure/cli.rb', line 35

def menu_helper
  list_destinations
  select_destination
end


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/travel_leisure/cli.rb', line 59

def print_destination(destination)
  puts ""
  puts "----------- #{destination.city}, #{destination.country} -----------".blue.bold
  puts ""
  puts "Best Time To Visit: #{destination.best_time_to_visit}".green.bold
  puts "\nTransportation: #{destination.transportation}".green.bold
  puts "\nWeather: #{destination.weather}".green.bold
  puts "\nKnow Before Visiting: #{destination.know_before_visiting}".green.bold
  puts "\nLanguage: #{destination.language}".green.bold
  puts "\nCurrency: #{destination.currency}".green.bold
  puts "\nWould you like to read more on #{destination.city}? Please enter 'Y' or 'N'".yellow.bold
    input = gets.strip.downcase
    case input
    when 'y' || 'yes'
      puts ""
      puts "More info:".yellow
      puts ""
      puts destination.description
      alt_menu
    when 'n' || 'no'
      alt_menu
    when 'exit'
      good_bye
    else
      puts ""
      puts "Sorry, I didn't understand that input.".red.bold
      alt_menu
    end
end

#select_destinationObject



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/travel_leisure/cli.rb', line 45

def select_destination
  puts "\nPlease enter the number of the travel guide you would like to access:".yellow.bold
    input = gets.strip
    destination = TravelLeisure::Destination.find(input.to_i)
    if input == "exit" || input == "e"
      good_bye
    elsif input.to_i.between?(1,TravelLeisure::Destination.all.length)
      print_destination(destination)
    else
      puts "Sorry! I didn't understand that input, please try again".red.bold
      select_destination
    end
end

#startObject



4
5
6
7
8
# File 'lib/travel_leisure/cli.rb', line 4

def start
  greeting
  TravelLeisure::Scraper.new.make_destinations
  menu
end