Class: KnoxRestaurants::CLI

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

Instance Method Summary collapse

Instance Method Details

#callObject

outputs to user



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

def call
  puts "Welcome to Knoxville!"
  KnoxRestaurants::API.fetch #fetches from API
    start
end

#display_cuisine_choicesObject



17
18
19
20
21
# File 'lib/Knox_Restaurants/cli.rb', line 17

def display_cuisine_choices
  @cuisine = KnoxRestaurants::Restaurant.get_cuisines.each.with_index(1) do |cuisine, idx|
    puts "#{idx}. #{cuisine}"
  end
end

#display_details(input) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/Knox_Restaurants/cli.rb', line 54

def display_details(input)
  r = @restaurant[input-1]
  
  puts <<~RESTAURANT
    Address: #{r.address}
    Phone number: #{r.phone_number}
    Website: #{r.url}
    Rating: #{r.rating} of 5
    Price Range: #{r.price}
    Reviews: #{r.reviews}
    RESTAURANT
  
end

#display_restaurants(input) ⇒ Object



38
39
40
41
42
# File 'lib/Knox_Restaurants/cli.rb', line 38

def display_restaurants(input)
  @restaurant = KnoxRestaurants::Restaurant.get_cuisine_restaurants(input).each.with_index(1) do |r, idx|
    puts "#{idx}. #{r.name}"
   end
end

#goodbyeObject



84
85
86
87
# File 'lib/Knox_Restaurants/cli.rb', line 84

def goodbye
  puts "Thanks for visiting Knoxville. Have a nice day."
  exit
end

#input_cuisine_choiceObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/Knox_Restaurants/cli.rb', line 23

def input_cuisine_choice
  puts "What are you in the mood for?"
  puts "Enter a valid number"
  puts "Enter 'end' to exit"
  input = gets.strip.downcase
    if  valid?(input, @cuisine)
      display_restaurants(input.to_i)
      puts "To find out more, enter the number for which restaurant you want"
    else
      puts "I don't understand. Please pick another cuisine"
      sleep(2)
      start
    end
end

#last_hurrahObject



75
76
77
78
79
80
81
82
# File 'lib/Knox_Restaurants/cli.rb', line 75

def last_hurrah
  puts "Would you like to pick another cuisine? Yes or No"
    if gets.chomp.downcase == "yes"
      start
    else
      goodbye
    end
end

#return_detailsObject



44
45
46
47
48
49
50
51
52
# File 'lib/Knox_Restaurants/cli.rb', line 44

def return_details
  puts "Please enter a valid restaurant number"
  restaurant = gets.chomp
    if valid?(restaurant, @restaurant)
      display_details(restaurant.to_i)
    else
      return_details
    end
end

#startObject



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

def start 
    display_cuisine_choices
    input_cuisine_choice
    return_details
    last_hurrah
end

#valid?(input, array) ⇒ Boolean

Returns:

  • (Boolean)


68
69
70
71
72
73
# File 'lib/Knox_Restaurants/cli.rb', line 68

def valid?(input,array)
  if input == "end"
    goodbye
  end
   input.to_i.between?(1, array.length)
end