Wasted Away Again in Margaritaville

Before I get into the technical aspects of the project I first have to state my biggest fail during the process of creating my phase one project.. and no its not that I was wasted the whole time (despite the title) its that I didn’t follow the instructions in the beginning. I developed my whole app “the_bar” to pull data from an API (application programming interface) which is basically a middle man between (in my case) my computer and an internet database. In my original case I was asking the middle man to go back and forth multiple times to complete the process of my program when the directions for the project clearly stated to only use the API once at the beginning of the of the program and use that info throughout. I wish I paid more attention to that before spending 30 + hours on it!! User error…. The light at the end of the tunnel is that most of the code I wrote still worked. In the end still a good amount of extra effort. Lesson learned!

So back to the title. My program is a virtual bartender that only serves different types of margaritas. I wanted to make the conversation between the bartender and the user as natural as possible so it felt a little more real and less mechanical. To do this I used the gets.chomp method which takes the user’s input and turns it into a string (text in a quotation ex: “I am a string”). I then hard coded in nearly every positive response i could think of to equal “yes”. It looks like this.

user_input = gets.chomp.downcase

if user_input == “yes” || user_input == “yes please” || user_input == “ok” || user_input == “please” || user_input == “okay” || user_input == “k” || user_input == “yeah” || user_input == “y” || user_input == “ya” || user_input == “yea” || user_input == “yep” || user_input == “sounds good” || user_input == “aight” || user_input == “alright” || user_input == “alrighty” || user_input == “sure” || user_input == “why not” || user_input == “absolutely” || user_input == “definitely” || user_input == “def” || user_input == “positive” || user_input == “i guess”

“yes”

It looks a bit crazy, but it worked haha. I think my next ruby gem will be a .yes method.

The most difficult part of my project was pulling out the ingredients for each cocktail. Since they were listed not listed in an array but individually.

This meant I had to go into the particular drink object that the user chose and pull out all the ingredients individually and turn them into an array that I could display to the user. I don’t particularly love the solution I made but it worked in the end. I make an att_accessor for the ingredients called @your_ingredients and since there was a maximum of 7 ingredients for a cocktail I used the .select method which can find items in an and return them in an array form. I then made my @your_ingredients = ingredient_1, ingredient_2 so on and so on all the way to ingredient_7. It then returned and array but there was a problem! For the cocktails with less than 7 ingredients (which was all but one) the empty ingredients returned nil for example: @your_ingredients = [“Tequila”, “Blue Curacao”, “Lime Juice”, “salt”, “nil”, “nil”, “nil”]. My solution to this was to use the uniq method on the @your_ingredients array. This method takes away any repeat values in an array so in the end there is one nil at the end of the arrays. I know its not the greatest solution but I was the only one that I could get to return what I wanted. While running the program the nil value looks like a line spacer which is actually nice. A bit machiavellian I know but sometimes the ends are justified by the means haha.