Class: RoadtripAdventures::CLI

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

Instance Method Summary collapse

Instance Method Details

#callObject



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

def call
  welcome
  RoadtripAdventures::Scraper.scrape_destinations
  list_destinations
  select_destination
end

#goodbyeObject



51
52
53
# File 'lib/roadtrip_adventures/cli.rb', line 51

def goodbye
  puts "So long!! May your journey be filled with new adventures and excitement!!".colorize(:yellow)
end

#list_adventures(destination_name) ⇒ Object



44
45
46
47
48
49
# File 'lib/roadtrip_adventures/cli.rb', line 44

def list_adventures(destination_name)
  adventure_arr = RoadtripAdventures::Adventure.list_adventure_names(destination_name)
  puts adventure_arr.map.with_index{|d, index| "#{index+1}. #{d.name}, #{d.price}"}
  puts "\n**********************************************************".colorize(:blue)
  puts "Please choose another destination 1-10 or 'exit' to leave.".colorize(:yellow)
end

#list_destinationsObject



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

def list_destinations
   puts "**********DESTINATIONS**********\n".colorize(:blue)
   @destination_arr = RoadtripAdventures::Destination.all
   puts  @destination_arr.map.with_index{|destination, index| "\t#{index+1}. #{destination.name}"}
   puts "\n********************************".colorize(:blue)
   puts "Select a destination from 1-10:".colorize(:yellow)
   puts "********************************".colorize(:blue)
end

#select_destinationObject



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

def select_destination
  input = nil

  while input != 'exit'
    input = gets.strip
    if input.to_i > 0 && input.to_i < 11
      destination_name = @destination_arr[input.to_i-1].name.strip
      destination_url = @destination_arr[input.to_i-1].url
      puts "******************** ".colorize(:blue) + "#{destination_name.upcase} ADVENTURES".colorize(:yellow) + " ********************\n".colorize(:blue)
      list_adventures(destination_name)
      puts "**********************************************************".colorize(:blue)
    elsif input != 'exit'
      puts "You've made an invalid choice! Make a selection from 1-10 or 'exit' to leave".colorize(:light_blue)
      list_destinations
      input = gets.strip

    end
  end
  goodbye
end

#welcomeObject



10
11
12
# File 'lib/roadtrip_adventures/cli.rb', line 10

def welcome
  puts "\nWELCOME TO ROADTRIP ADVENTURES!\n".colorize(:yellow)
end