Class: KnoxRestaurants::CLI
- Inherits:
-
Object
- Object
- KnoxRestaurants::CLI
- Defined in:
- lib/Knox_Restaurants/cli.rb
Instance Method Summary collapse
-
#call ⇒ Object
outputs to user.
- #display_cuisine_choices ⇒ Object
- #display_details(input) ⇒ Object
- #display_restaurants(input) ⇒ Object
- #goodbye ⇒ Object
- #input_cuisine_choice ⇒ Object
- #last_hurrah ⇒ Object
- #return_details ⇒ Object
- #start ⇒ Object
- #valid?(input, array) ⇒ Boolean
Instance Method Details
#call ⇒ Object
outputs to user
4 5 6 7 8 9 10 11 12 |
# File 'lib/Knox_Restaurants/cli.rb', line 4 def call KnoxRestaurants::API.fetch #fetches from API puts " -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-\n | Welcome to Knoxville! |\n -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-\n REST\n start\nend\n" |
#display_cuisine_choices ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/Knox_Restaurants/cli.rb', line 21 def display_cuisine_choices @cuisine = KnoxRestaurants::Restaurant.get_cuisines.each.with_index(1) do |cuisine, idx| puts " \#{idx}. \#{cuisine} \n REST\n end\nend\n" |
#display_details(input) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/Knox_Restaurants/cli.rb', line 87 def display_details(input) r = @restaurant[input-1] puts " Address: \#{r.address}\n Phone number: \#{r.phone_number}\n Rating: \#{r.rating} of 5\n Price Range: \#{r.price}\n Reviews: \#{r.reviews}\n Website: \#{r.url}\n REST\nend\n" |
#display_restaurants(input) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/Knox_Restaurants/cli.rb', line 65 def display_restaurants(input) @restaurant = KnoxRestaurants::Restaurant.get_cuisine_restaurants(input).each.with_index(1) do |r, idx| puts " \#{idx}. \#{r.name} \n REST\n end\nend\n" |
#goodbye ⇒ Object
120 121 122 123 124 125 126 127 |
# File 'lib/Knox_Restaurants/cli.rb', line 120 def goodbye puts " -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-\n | Thanks for visiting Knoxville. Have a nice day! |\n -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-\n REST\n exit\nend\n" |
#input_cuisine_choice ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/Knox_Restaurants/cli.rb', line 29 def input_cuisine_choice puts " -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-\n | What are you in the mood for? |\n -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-\n REST\n puts <<-REST\n -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-\n | Enter a valid number |\n -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-\n REST\n puts <<-REST\n -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-\n | Enter 'end' to exit |\n -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-\n REST\n input = gets.strip.downcase\n if valid?(input, @cuisine)\n display_restaurants(input.to_i)\n puts <<-REST\n -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-\n | To find out more, enter the |\n | number for the restaurant you want |\n -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-\n REST\n else\n puts <<-REST\n -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-\n | I don't understand. Please pick another cuisine |\n -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-\n REST\n sleep(2)\n start\n end\nend\n" |
#last_hurrah ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/Knox_Restaurants/cli.rb', line 107 def last_hurrah puts " -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-\n | Would you like to pick another cuisine? Yes or No |\n -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-\n REST\n if gets.chomp.downcase == \"yes\"\n start\n else\n goodbye\n end\nend\n" |
#return_details ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/Knox_Restaurants/cli.rb', line 73 def return_details puts " -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-\n | Please enter a valid restaurant number |\n -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-\n REST\n restaurant = gets.chomp\n if valid?(restaurant, @restaurant)\n display_details(restaurant.to_i)\n else\n return_details\n end\nend\n" |
#start ⇒ Object
14 15 16 17 18 19 |
# File 'lib/Knox_Restaurants/cli.rb', line 14 def start display_cuisine_choices input_cuisine_choice return_details last_hurrah end |
#valid?(input, array) ⇒ Boolean
100 101 102 103 104 105 |
# File 'lib/Knox_Restaurants/cli.rb', line 100 def valid?(input,array) if input == "end" goodbye end input.to_i.between?(1, array.length) end |