liquery 0.8.6 → 0.8.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config/environment.rb +0 -1
- data/lib/LiquerY/DrinkAPI.rb +17 -0
- data/lib/LiquerY/User.rb +58 -0
- data/lib/LiquerY/drink.rb +129 -0
- data/lib/LiquerY/version.rb +3 -0
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b64a9be0b8c33a8c4de89049079cb63841ee80fafd971cf4fd9e3bd6e5753bee
|
4
|
+
data.tar.gz: b0dab2bfc79660b28029c89187cacb7e4c13603864cd083fcc22abd44d346882
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7cf0ad09d958b96524dcc0c8d59662040ec47e38d4ecbe1a3d728e10c908cdada6bb8b8d4ca591eaa2c8045f77e78a0a33922422e0ffe29c1181819f9219711
|
7
|
+
data.tar.gz: 0d61c184c2a4d825d59abae64d662160216bdd25fd08ff0db162faab808e38038269ab9599a810342930bbbb6636ee73a290498bdf88b3e8ba649f6e4e773c6e
|
data/config/environment.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
class DrinkAPI
|
2
|
+
attr_reader :id_array
|
3
|
+
def initialize
|
4
|
+
data = open("https://www.thecocktaildb.com/api/json/v1/1/filter.php?c=Cocktail").read
|
5
|
+
doc = JSON.parse(data)
|
6
|
+
#key is ["drinks"] value is array of ingredients
|
7
|
+
@id_array = doc.first.last.each.with_object([]) do |id_hash, array|
|
8
|
+
array << id_hash["idDrink"]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def make_hash
|
13
|
+
self.id_array.each.with_object({}) do |id, drink_hash|
|
14
|
+
drink_hash[id] = JSON.parse(open("https://www.thecocktaildb.com/api/json/v1/1/lookup.php?i=#{id}").read).values.first[0]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/LiquerY/User.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
class User
|
2
|
+
attr_accessor :liked_drinks, :liked_ingredients, :disliked_drinks, :quiz_results, :okay_drinks, :great_drinks
|
3
|
+
|
4
|
+
@@all = []
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
self.liked_drinks = []
|
8
|
+
self.liked_ingredients = []
|
9
|
+
self.disliked_drinks = []
|
10
|
+
@@all << self
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.all
|
14
|
+
@@all
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.current_user
|
18
|
+
@@all[-1]
|
19
|
+
end
|
20
|
+
|
21
|
+
def list_liked_drinks
|
22
|
+
puts "Drinks you like:".cyan
|
23
|
+
puts "\n\t#{self.print_list(self.liked_drinks.uniq)}".light_blue
|
24
|
+
puts "\nDrinks we've recommended:".cyan
|
25
|
+
puts "\n\t#{self.print_list(self.quiz_results)}".light_blue
|
26
|
+
end
|
27
|
+
|
28
|
+
def list_disliked_drinks
|
29
|
+
"Drinks you dislike: #{self.names(disliked_drinks)}."
|
30
|
+
end
|
31
|
+
|
32
|
+
def print_list(array)
|
33
|
+
array.each.with_object("") do |drink, string|
|
34
|
+
if array.size == 1
|
35
|
+
string << drink.strDrink
|
36
|
+
elsif array.size == 2 && drink == array[0]
|
37
|
+
string << "#{drink.strDrink} "
|
38
|
+
elsif drink == array[-1]
|
39
|
+
string << "and #{drink.strDrink}"
|
40
|
+
else
|
41
|
+
string << "#{drink.strDrink}, "
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def names(drink_array)
|
47
|
+
drink_array.map {|drink| drink.strDrink}
|
48
|
+
end
|
49
|
+
|
50
|
+
def recent_choice
|
51
|
+
self.liked_drinks[-1]
|
52
|
+
end
|
53
|
+
|
54
|
+
def add_to_liked_ingredients
|
55
|
+
@liked_ingredients.concat((self.liked_drinks.map {|d| d.all_ingredients}).flatten.uniq)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
class Drink
|
2
|
+
attr_accessor :idDrink, :strDrink, :all_ingredients, :strIngredient1, :strIngredient2, :strIngredient3, :strIngredient4, :strIngredient5, :strIngredient6, :strIngredient7, :strIngredient8, :strIngredient9, :strMeasure1, :strMeasure2, :strMeasure3, :strMeasure4, :strMeasure5, :strMeasure6, :strMeasure7, :strMeasure8, :strInstructions, :palate
|
3
|
+
|
4
|
+
TEST_DRINKS = ["Boulevardier", "Cosmopolitan", "Dirty Martini", "Espresso Martini", "French Negroni", "Gimlet", "Gin Rickey", "Greyhound", "Lemon Drop", "Manhattan", "Martini", "Mojito", "Old Fashioned", "Pisco Sour", "The Last Word"]
|
5
|
+
DUMMY_DRINK = Drink.new.tap {|d| d.all_ingredients = ["a single bogus and insane ingredient that won't match anything"]}
|
6
|
+
|
7
|
+
@@all = []
|
8
|
+
|
9
|
+
def self.all
|
10
|
+
@@all.empty? ? Drink.new_from_hash : @@all
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.new_from_hash(hash = DrinkAPI.new.make_hash)
|
14
|
+
hash.each do |id, drink_array|
|
15
|
+
drink = self.new
|
16
|
+
drink.all_ingredients = []
|
17
|
+
|
18
|
+
correct_and_set_data(drink, drink_array)
|
19
|
+
|
20
|
+
concat_ingredients(drink)
|
21
|
+
|
22
|
+
filter_and_set_by_palate(drink)
|
23
|
+
|
24
|
+
@@all << drink unless drink.idDrink == "14133" #To filter out "Cosmopolitan Martini, which for some reason is included in the database twice under different spellings."
|
25
|
+
end
|
26
|
+
@@all
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.select_for_test
|
30
|
+
self.all.select {|d| TEST_DRINKS.include?(d.strDrink)}
|
31
|
+
end
|
32
|
+
|
33
|
+
def print_ingredients
|
34
|
+
self.all_ingredients.each.with_object("") do |ing, string|
|
35
|
+
if ing == self.all_ingredients[-1]
|
36
|
+
string << "and #{ing}."
|
37
|
+
else
|
38
|
+
string << "#{ing}, "
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.search_by_drink_name(name)
|
44
|
+
name_match = FuzzyMatch.new(Drink.all.map{|d| d.strDrink}).find("#{name}")
|
45
|
+
if Drink.all.find {|d| d.strDrink == name}
|
46
|
+
Drink.all.find {|d| d.strDrink == name}
|
47
|
+
elsif name_match
|
48
|
+
Drink.all.find {|d| d.strDrink == name_match }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.search_by_alcohol_name(name)
|
53
|
+
name_match = FuzzyMatch.new(Drink.all.map{|d| d.all_ingredients}.flatten).find("#{name}")
|
54
|
+
if Drink.all.map {|d| d.all_ingredients}.flatten.include?(name)
|
55
|
+
Drink.all.select {|d| d.all_ingredients.include?(name)}
|
56
|
+
elsif name_match
|
57
|
+
Drink.all.select {|d| d.all_ingredients.include?(name_match)}
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.find_ingredients_by_drink_name(name)
|
62
|
+
drink = self.search_by_drink_name(name)
|
63
|
+
system "clear"
|
64
|
+
puts "Drink Ingredients:".light_blue
|
65
|
+
puts "\n#{drink.strDrink} --".cyan
|
66
|
+
puts "#{drink.print_ingredients}".cyan
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.find_recipe_by_drink_name(name)
|
70
|
+
drink = self.search_by_drink_name(name)
|
71
|
+
system "clear"
|
72
|
+
puts "Drink Recipe:".light_blue
|
73
|
+
puts "\n#{drink.strDrink} --".cyan
|
74
|
+
puts "Ingredients: ".cyan + "#{drink.print_ingredients}".light_blue
|
75
|
+
puts "#{drink.strInstructions}".cyan
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.search_by_palate(palate)
|
79
|
+
Drink.all.select {|d| d.palate == palate}
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
def self.correct_and_set_data(drink, drink_array)
|
85
|
+
drink_array.each do |method, arg| ###REMOVE THIS ZERO WHEN YOU PULL FROM API!!!
|
86
|
+
if !(["strDrink", "strInstructions"].include?(method))
|
87
|
+
if drink.respond_to?("#{method}") && arg.is_a?(String) && arg.include?("Absolut")
|
88
|
+
drink.send("#{method}=", "Vodka") #Had to hardcode this in
|
89
|
+
#because for almost every drink they list a generic liquor
|
90
|
+
#as an ingredient, except for, frustratingly, certain vodka
|
91
|
+
#drinks, for which they give a brand name Absolut variety
|
92
|
+
#that messes up my algorithm
|
93
|
+
elsif drink.respond_to?("#{method}") && arg.is_a?(String) && (arg.include?("lemon") || arg.include?("Lemon"))
|
94
|
+
drink.send("#{method}=", "Lemon Juice")
|
95
|
+
drink.send("strIngredient9=", "Simple Syrup")
|
96
|
+
elsif drink.respond_to?("#{method}") && arg.is_a?(String) && (arg.include?("Sugar") || arg.include?("Simple"))
|
97
|
+
drink.send("#{method}=", "Simple Syrup")
|
98
|
+
elsif drink.respond_to?("#{method}") && arg.is_a?(String) && arg.include?("Lime")
|
99
|
+
drink.send("#{method}=", "Lime Juice")
|
100
|
+
elsif drink.respond_to?("#{method}") && arg != " " && arg != ""
|
101
|
+
drink.send("#{method}=", arg)
|
102
|
+
end
|
103
|
+
elsif drink.respond_to?("#{method}") && arg != " " && arg != ""
|
104
|
+
drink.send("#{method}=", arg)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.filter_and_set_by_palate(drink)
|
110
|
+
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?
|
111
|
+
drink.palate = "creamy"
|
112
|
+
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?
|
113
|
+
drink.palate = "bright"
|
114
|
+
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?
|
115
|
+
drink.palate = "sweet"
|
116
|
+
else
|
117
|
+
drink.palate = "dry"
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def self.concat_ingredients(drink)
|
122
|
+
drink.instance_variables.map{|v|v.to_s.tr('@', '')}.select{|v| v.match(/^strIng/)}.each do |v|
|
123
|
+
unless (drink.send("#{v}") == nil || drink.all_ingredients.include?(drink.send("#{v}")))
|
124
|
+
drink.all_ingredients << drink.send("#{v}")
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: liquery
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Johnson
|
@@ -119,6 +119,10 @@ files:
|
|
119
119
|
- bin/liquery
|
120
120
|
- config/environment.rb
|
121
121
|
- lib/LiquerY/CLI.rb
|
122
|
+
- lib/LiquerY/DrinkAPI.rb
|
123
|
+
- lib/LiquerY/User.rb
|
124
|
+
- lib/LiquerY/drink.rb
|
125
|
+
- lib/LiquerY/version.rb
|
122
126
|
- lib/liquery.rb
|
123
127
|
homepage: https://github.com/aaj3f/LiquerY
|
124
128
|
licenses:
|