class Drink

Constants

DUMMY_DRINK
TEST_DRINKS

Attributes

all_ingredients[RW]
idDrink[RW]
palate[RW]
strDrink[RW]
strIngredient1[RW]
strIngredient2[RW]
strIngredient3[RW]
strIngredient4[RW]
strIngredient5[RW]
strIngredient6[RW]
strIngredient7[RW]
strIngredient8[RW]
strIngredient9[RW]
strInstructions[RW]
strMeasure1[RW]
strMeasure2[RW]
strMeasure3[RW]
strMeasure4[RW]
strMeasure5[RW]
strMeasure6[RW]
strMeasure7[RW]
strMeasure8[RW]

Public Class Methods

all() click to toggle source
# File lib/LiquerY/drink.rb, line 9
def self.all
  @@all.empty? ? Drink.new_from_hash : @@all
end
find_ingredients_by_drink_name(name) click to toggle source
# File lib/LiquerY/drink.rb, line 61
def self.find_ingredients_by_drink_name(name)
  drink = self.search_by_drink_name(name)
  system "clear"
  puts "Drink Ingredients:".light_blue
  puts "\n#{drink.strDrink} --".cyan
  puts "#{drink.print_ingredients}".cyan
end
find_recipe_by_drink_name(name) click to toggle source
# File lib/LiquerY/drink.rb, line 69
def self.find_recipe_by_drink_name(name)
  drink = self.search_by_drink_name(name)
  system "clear"
  puts "Drink Recipe:".light_blue
  puts "\n#{drink.strDrink} --".cyan
  puts "Ingredients: ".cyan + "#{drink.print_ingredients}".light_blue
  puts "#{drink.strInstructions}".cyan
end
new_from_hash(hash = DrinkAPI.new.make_hash) click to toggle source
# File lib/LiquerY/drink.rb, line 13
def self.new_from_hash(hash = DrinkAPI.new.make_hash)
  hash.each do |id, drink_array|
    drink = self.new
    drink.all_ingredients = []

    correct_and_set_data(drink, drink_array)

    concat_ingredients(drink)

    filter_and_set_by_palate(drink)

    @@all << drink unless drink.idDrink == "14133" #To filter out "Cosmopolitan Martini, which for some reason is included in the database twice under different spellings."
  end
  @@all
end
search_by_alcohol_name(name) click to toggle source
# File lib/LiquerY/drink.rb, line 52
def self.search_by_alcohol_name(name)
  name_match = FuzzyMatch.new(Drink.all.map{|d| d.all_ingredients}.flatten).find("#{name}")
  if Drink.all.map {|d| d.all_ingredients}.flatten.include?(name)
    Drink.all.select {|d| d.all_ingredients.include?(name)}
  elsif name_match
    Drink.all.select {|d| d.all_ingredients.include?(name_match)}
  end
end
search_by_drink_name(name) click to toggle source
# File lib/LiquerY/drink.rb, line 43
def self.search_by_drink_name(name)
  name_match = FuzzyMatch.new(Drink.all.map{|d| d.strDrink}).find("#{name}")
  if Drink.all.find {|d| d.strDrink == name}
    Drink.all.find {|d| d.strDrink == name}
  elsif name_match
    Drink.all.find {|d| d.strDrink == name_match }
  end
end
search_by_palate(palate) click to toggle source
# File lib/LiquerY/drink.rb, line 78
def self.search_by_palate(palate)
  Drink.all.select {|d| d.palate == palate}
end
select_for_test() click to toggle source
# File lib/LiquerY/drink.rb, line 29
def self.select_for_test
  self.all.select {|d| TEST_DRINKS.include?(d.strDrink)}
end

Private Class Methods

concat_ingredients(drink) click to toggle source
# File lib/LiquerY/drink.rb, line 121
def self.concat_ingredients(drink)
  drink.instance_variables.map{|v|v.to_s.tr('@', '')}.select{|v| v.match(/^strIng/)}.each do |v|
    unless (drink.send("#{v}") == nil || drink.all_ingredients.include?(drink.send("#{v}")))
      drink.all_ingredients << drink.send("#{v}")
    end
  end
end
correct_and_set_data(drink, drink_array) click to toggle source
# File lib/LiquerY/drink.rb, line 84
def self.correct_and_set_data(drink, drink_array)
  drink_array.each do |method, arg| ###REMOVE THIS ZERO WHEN YOU PULL FROM API!!!
    if !(["strDrink", "strInstructions"].include?(method))
      if drink.respond_to?("#{method}") && arg.is_a?(String) && arg.include?("Absolut")
        drink.send("#{method}=", "Vodka") #Had to hardcode this in
        #because for almost every drink they list a generic liquor
        #as an ingredient, except for, frustratingly, certain vodka
        #drinks, for which they give a brand name Absolut variety
        #that messes up my algorithm
      elsif drink.respond_to?("#{method}") && arg.is_a?(String) && (arg.include?("lemon") || arg.include?("Lemon"))
        drink.send("#{method}=", "Lemon Juice")
        drink.send("strIngredient9=", "Simple Syrup")
      elsif drink.respond_to?("#{method}") && arg.is_a?(String) && (arg.include?("Sugar") || arg.include?("Simple"))
        drink.send("#{method}=", "Simple Syrup")
      elsif drink.respond_to?("#{method}") && arg.is_a?(String) && arg.include?("Lime")
        drink.send("#{method}=", "Lime Juice")
      elsif drink.respond_to?("#{method}") && arg != " " && arg != ""
        drink.send("#{method}=", arg)
      end
    elsif drink.respond_to?("#{method}") && arg != " " && arg != ""
      drink.send("#{method}=", arg)
    end
  end
end
filter_and_set_by_palate(drink) click to toggle source
# File lib/LiquerY/drink.rb, line 109
def self.filter_and_set_by_palate(drink)
  if (drink.all_ingredients.map {|d|d.downcase} & ["cream", "milk", "kahlua", "bailey", "bailey\'s irish cream", "creme de cacao", "white creme de menthe", "hot chocolate", "coffee liqueur", "chocolate liqueur", "pina colada mix"]).any?
    drink.palate = "creamy"
  elsif (drink.all_ingredients.map {|d|d.downcase} & ["lime juice", "lemon juice"]).any? && !(drink.all_ingredients.map {|d|d.downcase}.include?("simple syrup")) || (drink.all_ingredients.map {|d|d.downcase} & ["sour mix", "sweet and sour", "pisco"]).any?
      drink.palate = "bright"
  elsif (drink.all_ingredients.map {|d|d.downcase} & ["simple syrup", "grenadine", "creme de cassis", "apple juice", "cranberry juice", "pineapple juice", "maraschino cherry", "maraschino liqueur", "grape soda", "kool-aid"]).any?
    drink.palate = "sweet"
  else
    drink.palate = "dry"
  end
end

Public Instance Methods

print_ingredients() click to toggle source