tee_reverser 0.0.0 → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/tee_reverser/pantry.rb +16 -0
- data/lib/tee_reverser/recipelist.rb +19 -0
- data/lib/tee_reverser/reverser.rb +25 -0
- data/lib/tee_reverser.rb +42 -4
- metadata +7 -4
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'CSV'
|
2
|
+
|
3
|
+
class Pantry #establishes user ingredients
|
4
|
+
attr_accessor :filepath
|
5
|
+
attr_reader :list
|
6
|
+
|
7
|
+
def initialize(filepath)
|
8
|
+
@filepath = filepath
|
9
|
+
@list = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def parse
|
13
|
+
CSV.foreach(self.filepath) {|row| list << row}
|
14
|
+
list.flatten!
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class RecipeList #funnels Yummly results into workable hash
|
2
|
+
attr_accessor :result
|
3
|
+
attr_reader :recipehash
|
4
|
+
|
5
|
+
def initialize(result)
|
6
|
+
@result = result
|
7
|
+
@recipehash = {}
|
8
|
+
# @recipehash = {"General Tso\u2019s Tofu"=>["sherry wine", "green bell pepper", "canola oil", "soy sauce", "green onions", "ginger", "firm tofu", "red pepper flakes", "red bell pepper", "white onion", "egg substitute", "sugar", "white vinegar", "vegetable stock", "minced garlic", "cornstarch", 0], "General Tso\u2019s Chicken and Broccoli"=>["brown rice", "sauce", "broccoli", "chicken", 0], "Laura\u2019s General Tso's Seitan"=>["soy sauce", "gingerroot", "seitan", "eggs", "garlic cloves", "vegetable oil", "sugar", "chiles", "water", "rice", "distilled white vinegar", "cornstarch", 0]}
|
9
|
+
end
|
10
|
+
|
11
|
+
def listbuilder
|
12
|
+
recipes = result.collect {|recipe| recipe.name}
|
13
|
+
elements = result.collect {|recipe| recipe.ingredients}
|
14
|
+
for num in 0..recipes.size-1
|
15
|
+
recipehash[recipes[num]]=elements[num]
|
16
|
+
end
|
17
|
+
recipehash.each {|k,v| v<<0}
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class Reverser
|
2
|
+
include Enumerable
|
3
|
+
attr_accessor :pantrylist, :tee
|
4
|
+
attr_reader :eat
|
5
|
+
|
6
|
+
def initialize(pantrylist, tee)
|
7
|
+
@pantrylist = pantrylist
|
8
|
+
@tee = tee
|
9
|
+
@eat = Hash.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def reverse
|
13
|
+
tee.each do |k,v|
|
14
|
+
templist = v.join(" ")
|
15
|
+
for num in 0..pantrylist.size-1
|
16
|
+
tee[k][-1]+=1 if /#{pantrylist[num]}/.match(templist)
|
17
|
+
end
|
18
|
+
puts eat.is_a? Hash
|
19
|
+
end
|
20
|
+
puts tee
|
21
|
+
eat = tee
|
22
|
+
puts eat
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/lib/tee_reverser.rb
CHANGED
@@ -1,5 +1,43 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
require 'yummly'
|
2
|
+
require './tee_reverser/reverser.rb'
|
3
|
+
require './tee_reverser/recipelist.rb'
|
4
|
+
require './tee_reverser/pantry.rb'
|
5
|
+
|
6
|
+
module TeeReverser
|
7
|
+
|
8
|
+
Yummly.configure do |config|
|
9
|
+
config.app_id = "bddcbcff"
|
10
|
+
config.app_key = "9245c33f2cc6d6bedb65715d3fb66c61"
|
11
|
+
end
|
12
|
+
|
13
|
+
puts "Please give me the filepath of your pantry list, in .txt format."
|
14
|
+
puts "Your list will ideally have any each ingredient you wish to itemize in its own line."
|
15
|
+
|
16
|
+
location = gets.chomp
|
17
|
+
|
18
|
+
#ensures only proper objects get loaded
|
19
|
+
until /.txt/.match(location.to_str) && File.exists?("#{location}") do
|
20
|
+
puts "Please give me a valid filepath and name. File must exist and be in *.txt format."
|
21
|
+
location = gets.chomp
|
22
|
+
end
|
23
|
+
|
24
|
+
goods = Pantry.new(location)
|
25
|
+
# puts goods.filepath
|
26
|
+
goods.parse
|
27
|
+
|
28
|
+
|
29
|
+
puts "What kind of dish would you like to make?"
|
30
|
+
wishlist = gets.chomp
|
31
|
+
query = Yummly.search("#{wishlist}")
|
32
|
+
meal = RecipeList.new(query)
|
33
|
+
meal.listbuilder
|
34
|
+
|
35
|
+
#tests
|
36
|
+
# query={"meal" => 1}
|
37
|
+
# meal = RecipeList.new(query)
|
38
|
+
|
39
|
+
decision = Reverser.new(goods.list, meal.recipehash)
|
40
|
+
decision.reverse
|
41
|
+
puts decision.tee.max_by{|k,v| v[-1]}
|
42
|
+
|
5
43
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tee_reverser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,15 +9,18 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-12-08 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
|
-
description:
|
14
|
+
description: Determines optimal recipe given pantry contents. Powered by Yummly.
|
15
15
|
email: steven.b.xu@gmail.com
|
16
16
|
executables: []
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
20
|
- lib/tee_reverser.rb
|
21
|
+
- lib/tee_reverser/pantry.rb
|
22
|
+
- lib/tee_reverser/recipelist.rb
|
23
|
+
- lib/tee_reverser/reverser.rb
|
21
24
|
homepage: http://rubygems.org/gems/tee_reverser
|
22
25
|
licenses:
|
23
26
|
- ! '?'
|
@@ -42,5 +45,5 @@ rubyforge_project:
|
|
42
45
|
rubygems_version: 1.8.24
|
43
46
|
signing_key:
|
44
47
|
specification_version: 3
|
45
|
-
summary:
|
48
|
+
summary: Basic functions defined
|
46
49
|
test_files: []
|