Class: Liquery::CLI
- Inherits:
-
Object
- Object
- Liquery::CLI
- Defined in:
- lib/LiquerY/CLI.rb
Instance Method Summary collapse
- #add_or_return(drink) ⇒ Object
- #calculate_great_drinks ⇒ Object
- #calculate_okay_drinks ⇒ Object
- #call ⇒ Object
- #compile ⇒ Object
-
#drink_quiz ⇒ Object
———— ## QUIZ METHODS ## ———— ##.
- #exit ⇒ Object
- #list_liked_and_recommended ⇒ Object
-
#list_menu_options ⇒ Object
———— ## MENU METHODS ## ———— ##.
- #list_search_options ⇒ Object
- #main_menu ⇒ Object
- #menu_search_by_alcohol ⇒ Object
- #menu_search_by_drink_name(name = nil) ⇒ Object
- #menu_search_by_palate_keyword ⇒ Object
- #offer_main_test ⇒ Object
- #offer_sub_test ⇒ Object
- #return_quiz_results ⇒ Object
- #safe_input?(input, array) ⇒ Boolean
- #test_dislikes ⇒ Object
- #user_local_ingredient_search ⇒ Object
- #user_local_recipe_search ⇒ Object
- #welcome ⇒ Object
Instance Method Details
#add_or_return(drink) ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/LiquerY/CLI.rb', line 213 def add_or_return(drink) puts "\nType ".cyan + "[menu]".light_blue + " to return to the previous menu, or".cyan puts "type ".cyan + "[add]".light_blue + " to add this drink to your list of \'liked drinks\'".cyan begin print "Your selection: ".cyan input = gets.chomp case input when "add" User.current_user.liked_drinks << drink puts "\nAwesome! We've added ".light_blue + drink.strDrink.upcase.cyan + " to your list of \'liked drinks\'.".light_blue puts "\nPress [Enter] to return to the main menu..." STDIN.getch else puts "Whoops, \'#{input}\' isn't an option!".light_blue unless input == "menu" end end until input == "menu" || input == "add" end |
#calculate_great_drinks ⇒ Object
353 354 355 356 357 358 359 360 361 362 363 |
# File 'lib/LiquerY/CLI.rb', line 353 def calculate_great_drinks array = Drink.all.select do |drink| # 5. calculate User.current_user.s "great_drinks array" if (User.current_user.liked_drinks + User.current_user.disliked_drinks + User.current_user.quiz_results).include?(drink) false elsif drink.all_ingredients.size < 4 (drink.all_ingredients & User.current_user.liked_ingredients).size > 1 && (drink.all_ingredients & User.current_user.disliked_drinks[-1].all_ingredients).size <= 1 else (drink.all_ingredients & User.current_user.liked_ingredients).size > 2 && (drink.all_ingredients & User.current_user.disliked_drinks[-1].all_ingredients).size <= 1 end end end |
#calculate_okay_drinks ⇒ Object
341 342 343 344 345 346 347 348 349 350 351 |
# File 'lib/LiquerY/CLI.rb', line 341 def calculate_okay_drinks Drink.all.select do |drink| #4. calculate User.current_user.s "okay_drinks" array if (User.current_user.liked_drinks + User.current_user.disliked_drinks + User.current_user.quiz_results).include?(drink) false elsif drink.all_ingredients.size < 4 (drink.all_ingredients & User.current_user.liked_ingredients).size > 0 && (drink.all_ingredients & User.current_user.disliked_drinks[-1].all_ingredients).size <= 1 else (drink.all_ingredients & User.current_user.liked_ingredients).size > 1 && (drink.all_ingredients & User.current_user.disliked_drinks[-1].all_ingredients).size <= 1 end end end |
#call ⇒ Object
3 4 5 6 7 |
# File 'lib/LiquerY/CLI.rb', line 3 def call welcome compile end |
#compile ⇒ Object
32 33 34 35 36 37 |
# File 'lib/LiquerY/CLI.rb', line 32 def compile spinner = ::TTY::Spinner.new(" [:spinner]".light_blue, format: :bouncing) spinner.auto_spin Drink.all spinner.stop('Done!'.cyan) end |
#drink_quiz ⇒ Object
———— ## QUIZ METHODS ## ———— ##
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/LiquerY/CLI.rb', line 239 def drink_quiz puts "\nAre you ready to take our quiz? [Press Enter to begin]..." STDIN.getch system "clear" User.current_user || User.new self.offer_main_test self.offer_sub_test puts "\nDepending on your answers, we may have a few" puts "more questions for you... [Press Enter to continue]" STDIN.getch system "clear" self.test_dislikes User.current_user.quiz_results ||= [] User.current_user.okay_drinks = (self.calculate_okay_drinks || []) User.current_user.great_drinks = (self.calculate_great_drinks || []) puts "\nThanks for completing our quiz!! Now give us just one second as" puts "we find a drink you're sure to enjoy! [Press Enter to Continue...]" STDIN.getch system "clear" self.return_quiz_results puts "\nWe're ready to return to the main menu! [Press Enter to continue]..." STDIN.getch system "clear" self. end |
#exit ⇒ Object
231 232 233 |
# File 'lib/LiquerY/CLI.rb', line 231 def exit puts "\nThanks for stopping by! Have a great day!".cyan end |
#list_liked_and_recommended ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/LiquerY/CLI.rb', line 84 def list_liked_and_recommended puts "Liked & Recommended Drinks:".light_blue User.current_user.list_liked_drinks puts "\nWould you like to see...".cyan + "\n[1.]".light_blue + " the ingredients for one of these drinks or ".cyan + "\n[2.]".light_blue + " learn how to mix one of them?".cyan begin print "Enter ".cyan + "\"1\"".light_blue + ", ".cyan + "\"2\"".light_blue + ", or ".cyan + "\"menu\"".light_blue + " to return to menu... ".cyan input = gets.chomp case input when "1" self.user_local_ingredient_search self. when "2" self.user_local_recipe_search self. when "menu" self. else puts "Whoops, \'#{input}\' isn't an option!".light_blue end end until ["1", "2", "menu"].include?(input) end |
#list_menu_options ⇒ Object
———— ## MENU METHODS ## ———— ##
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/LiquerY/CLI.rb', line 60 def puts "\n\t[1.] ".cyan + "See a list of your liked & recommended drinks".light_blue puts "\t[2.] ".cyan + "Search our entire repertoire of cocktails".light_blue puts "\t[3.] ".cyan + "Take our quiz again to update your preferences".light_blue puts "\t...or type ".light_blue + "\'exit\'".cyan + " to leave the app.".light_blue begin print "\nYour selection: ".cyan input = gets.chomp case input when "1" system "clear" self.list_liked_and_recommended when "2" self. when "3" self.drink_quiz when "exit" self.exit else puts "Whoops, \'#{input}\' isn't an option!".light_blue end end until ["1", "2", "3", "exit"].include?(input) end |
#list_search_options ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/LiquerY/CLI.rb', line 126 def system "clear" puts "Search Cocktails:".light_blue puts "How would you like to begin your search?".cyan puts "\n\t[1.] ".cyan + "Search by variety of alcohol or ingredient".light_blue puts "\t[2.] ".cyan + "Search by name of drink".light_blue puts "\t[3.] ".cyan + "Search by palate keywords\n".light_blue begin print "Your selection: ".cyan input = gets.chomp case input when "1" self. self. when "2" self. self. when "3" self. self. else puts "Whoops, \'#{input}\' isn't an option!".light_blue end end until ["1", "2", "3"].include?(input) end |
#main_menu ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/LiquerY/CLI.rb', line 39 def if !(User.current_user) puts "\nIt seems that you're here for the first time!".light_blue puts "To start, we'll have you begin by taking our quiz,".light_blue puts "so that we can get a sense for your likes & dislikes!".light_blue self.drink_quiz else system "clear" puts "Main Menu:".light_blue puts "Now that you've completed our quiz, we have a few".cyan puts "other services that may be helpful to you!".cyan self. end end |
#menu_search_by_alcohol ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/LiquerY/CLI.rb', line 152 def print "\nType the alcohol or ingredient name here: ".light_blue name = gets.chomp drink_array = Drink.search_by_alcohol_name(name) puts "\nHere are all the drinks we know with ".cyan + "#{name.upcase} ".light_blue + "in them:".cyan a = drink_array.each.with_index(1) {|d, i| puts "\t#{i}. #{d.strDrink}".light_blue} puts "Which drink would you like to know more about?".cyan begin print "Type the number of the drink here: ".cyan input = gets.chomp end until self.safe_input?(input, a) == true self.(a[input.to_i - 1].strDrink) end |
#menu_search_by_drink_name(name = nil) ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/LiquerY/CLI.rb', line 166 def (name = nil) if !(name) print "\nType the drink name here: ".light_blue name = gets.chomp end drink = Drink.search_by_drink_name(name) puts "\nWould you like to see the ".cyan + "[recipe]".light_blue + " or ".cyan + "[ingredients]".light_blue + " of #{drink.strDrink.match(/^[aeiou]/i) ? "an" : "a"} #{drink.strDrink.upcase}?".cyan puts "...or would you like to ".cyan + "[add]".light_blue + " it to your list of \'liked drinks\'?".cyan begin print "Your selection: ".cyan input = gets.chomp case input when "recipe" Drink.find_recipe_by_drink_name(drink.strDrink) self.add_or_return(drink) when "ingredients" Drink.find_ingredients_by_drink_name(drink.strDrink) self.add_or_return(drink) when "add" User.current_user.liked_drinks << drink puts "\nAwesome! We've added ".light_blue + drink.strDrink.upcase.cyan + " to your list of \'liked drinks\'.".light_blue puts "\nPress [Enter] to return to the main menu..." STDIN.getch else puts "Whoops, \'#{input}\' isn't an option!".light_blue end end until input == "recipe" || input == "ingredients" || input == "add" || input == "menu" end |
#menu_search_by_palate_keyword ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/LiquerY/CLI.rb', line 195 def puts "\nWould you like to search for a ".light_blue + "dry".cyan + ", ".light_blue + "sweet".cyan + ", ".light_blue + "creamy".cyan + ", or ".light_blue + "bright ".cyan + "drink?".light_blue begin print "Your selection: ".cyan input = gets.chomp puts "Whoops, \'#{input}\' isn't an option!".light_blue unless ["dry", "sweet", "creamy", "bright"].include?(input) end until ["dry", "sweet", "creamy", "bright"].include?(input) drink_array = Drink.search_by_palate(input) puts "Here are all the drinks we know with a ".cyan + "#{input.upcase} ".light_blue + "palate:".cyan a = drink_array.each.with_index(1) {|d, i| puts "\t#{i}. #{d.strDrink}".light_blue} puts "Which drink would you like to know more about?".cyan begin print "Type the number of the drink here: ".cyan input = gets.chomp end until self.safe_input?(input, a) == true self.(a[input.to_i - 1].strDrink) end |
#offer_main_test ⇒ Object
272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/LiquerY/CLI.rb', line 272 def offer_main_test puts "LiquerY Quiz:".light_blue puts "Listed below are some classic cocktails. Pick the one you enjoy the most!".cyan a = Drink.select_for_test.each.with_index(1) { |x, i| puts "#{i}. #{x.strDrink}".center(30)} begin print "Your favorite: ".cyan input = gets.chomp end until self.safe_input?(input, a) == true User.current_user.liked_drinks << a[input.to_i - 1] system "clear" puts "LiquerY Quiz:".light_blue puts "Gotcha! So of those drinks, your favorite is #{User.current_user.recent_choice.strDrink.match(/^[aeiou]/i) ? "an" : "a"} #{User.current_user.recent_choice.strDrink}?".cyan end |
#offer_sub_test ⇒ Object
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
# File 'lib/LiquerY/CLI.rb', line 286 def offer_sub_test puts "\nIf you had to pick one other drink from this smaller list,".light_blue puts "what would it be?".light_blue b = Drink.select_for_test.each.with_object([]) do |drink, array| User.current_user.recent_choice.all_ingredients.each do |ingredient| array << drink if drink.all_ingredients.include?(ingredient) end end.uniq.reject{|d| d == User.current_user.recent_choice} b.each.with_index(1) { |x, i| puts "#{i}. #{x.strDrink}".center(30)} begin print "Your choice: ".light_blue input = gets.chomp end until self.safe_input?(input, b) == true User.current_user.liked_drinks << b[input.to_i - 1] User.current_user.add_to_liked_ingredients system "clear" puts "LiquerY Quiz:".light_blue puts "Super! So although your 1st choice was #{User.current_user.liked_drinks[-2].strDrink.match(/^[aeiou]/i) ? "an" : "a"} #{User.current_user.liked_drinks[-2].strDrink},".cyan puts "you also could find yourself enjoying #{User.current_user.recent_choice.strDrink.match(/^[aeiou]/i) ? "an" : "a"} #{User.current_user.recent_choice.strDrink}.".cyan end |
#return_quiz_results ⇒ Object
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 |
# File 'lib/LiquerY/CLI.rb', line 365 def return_quiz_results User.current_user.great_drinks.size > 1 ? drink = User.current_user.great_drinks.sample : drink = User.current_user.okay_drinks.sample User.current_user.quiz_results << drink if Drink.select_for_test.include?(drink) puts "The answer was under our noses the entire time!".center(59).light_blue puts "We know we've asked you about this drink in the list above,".light_blue puts "but we're totally positive that you would love #{User.current_user.quiz_results[-1].strDrink.match(/^[aeiou]/i) ? "an" : "a"}".center(59).light_blue puts "\n" puts "#{drink.strDrink}!".center(59).cyan puts "It's made with #{drink.print_ingredients}".center(59).cyan puts "\n" puts "Give it a whirl, if you haven't tried one before!".center(59).light_blue puts "\n" elsif User.current_user.great_drinks.include?(drink) puts "So, we had to look into some of our more obscure".center(61).light_blue puts "cocktail recipes to find something just perfect for you".center(61).light_blue puts "but we're still totally certain that you're going to love it!".light_blue puts "\n" puts "The #{drink.strDrink}!".center(61).cyan puts "It's made with #{drink.print_ingredients}".center(61).cyan puts "\n" puts "Be sure to give it a taste!".center(61).light_blue puts "\n" else puts "We have to admit it... you nearly stumped us there!".center(64).light_blue puts "Sometimes drink preferences aren't exactly data science,".light_blue puts "but we're still decently confident that you'd enjoy #{drink.strDrink.match(/^[aeiou]/i) ? "an" : "a"}".center(64).light_blue puts "\n" puts "#{drink.strDrink}!".center(64).cyan puts "It's made with #{drink.print_ingredients}".center(64).cyan puts "\n" puts "Be sure to give it a taste!".center(64).light_blue puts "\n" end end |
#safe_input?(input, array) ⇒ Boolean
401 402 403 404 405 406 407 408 409 |
# File 'lib/LiquerY/CLI.rb', line 401 def safe_input?(input, array) input_max_range = array.size if (1..input_max_range).include?(input.to_i) true else puts "Sorry, that selection is invalid. Mind trying again?".light_blue false end end |
#test_dislikes ⇒ Object
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
# File 'lib/LiquerY/CLI.rb', line 307 def test_dislikes bad_drinks = Drink.select_for_test.select do |drink| User.current_user.liked_ingredients.size >= 10 ? (drink.all_ingredients & User.current_user.liked_ingredients).size < 2 : (drink.all_ingredients & User.current_user.liked_ingredients).empty? end bad_drinks -= User.current_user.disliked_drinks unless bad_drinks.empty? puts "LiquerY Quiz:".light_blue puts "Given the cocktails you've identified so far, we're noticing".cyan #3. test for dislikes puts "that you might not enjoy the palates of some of these drinks:".cyan bad_drinks.each.with_index(1) { |x, i| puts "#{i}. #{x.strDrink}".center(30)} puts "Is there one drink on this list that you absolutely cannot stand?".cyan begin print "If so, type that drink's number, otherwise type [none]: ".light_blue input = gets.chomp end until (self.safe_input?(input, bad_drinks) == true) || (input == "none") if input == "none" User.current_user.disliked_drinks << Drink::DUMMY_DRINK if User.current_user.disliked_drinks.empty? system "clear" puts "LiquerY Quiz:".light_blue puts "Perfect! It makes our job a little easier if you have an open mind & palate!".cyan else User.current_user.disliked_drinks << bad_drinks[input.to_i - 1] User.current_user.liked_drinks -= (User.current_user.liked_drinks & User.current_user.disliked_drinks) system "clear" puts "LiquerY Quiz:".light_blue puts "Blech! You just do not enjoy #{User.current_user.disliked_drinks[-1].strDrink.match(/^[aeiou]/i) ? "an" : "a"} #{User.current_user.disliked_drinks[-1].strDrink}.".cyan puts "We hear you! And that's great to know!".cyan end else # i.e. if bad_drinks.empty? puts "LiquerY Quiz:".light_blue puts "Actually, we don't think we have any further questions for you!".cyan end end |
#user_local_ingredient_search ⇒ Object
106 107 108 109 110 111 112 113 114 |
# File 'lib/LiquerY/CLI.rb', line 106 def user_local_ingredient_search puts "\nWhich drink would you like to see the ingredients for?".light_blue print "Type the drink name here: ".light_blue input = gets.chomp.capitalize Drink.find_ingredients_by_drink_name(input) puts "\n--------------------------------------".light_blue puts "\nPress [Enter] to return to the main menu..." STDIN.getch end |
#user_local_recipe_search ⇒ Object
116 117 118 119 120 121 122 123 124 |
# File 'lib/LiquerY/CLI.rb', line 116 def user_local_recipe_search puts "\nWhich drink would you like to see mixing instructions for?".light_blue print "Type the drink name here: ".light_blue input = gets.chomp.capitalize Drink.find_recipe_by_drink_name(input) puts "\n--------------------------------------".light_blue puts "\nPress [Enter] to return to the main menu..." STDIN.getch end |
#welcome ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/LiquerY/CLI.rb', line 9 def welcome puts "\n -- Welcome to LiquerY --\n\n Liquery is a games-style CLI app\n built to help its users better understand\n their palates for cocktails & drinks.\n\n We hope you have fun playing around with our app,\nand we hope that, in the process, we can help you learn\n about new & exciting beverages to enjoy,\nwhether you're out on the town or entertaining at home!\n\n Please wait just a moment\n as we compile our database of cocktails\n and user preferences!\n\n ----------------------------\n\n EOC\nend\n".cyan |