tee_reverser 0.0.5 → 0.1.0
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/execute.rb +1 -0
- data/lib/tee_reverser/pantry.rb +11 -2
- data/lib/tee_reverser/recipe_list.rb +11 -2
- data/lib/tee_reverser/reverser.rb +17 -2
- data/lib/tee_reverser/version.rb +1 -3
- data/lib/tee_reverser.rb +10 -9
- metadata +5 -4
data/lib/tee_reverser/execute.rb
CHANGED
data/lib/tee_reverser/pantry.rb
CHANGED
@@ -1,14 +1,23 @@
|
|
1
1
|
require 'CSV'
|
2
|
-
|
3
|
-
|
2
|
+
# This class is responsible for parsing the user ingredients, delivered
|
3
|
+
# in a .txt file, and putting it into an array that Reverser can
|
4
|
+
# work with.
|
5
|
+
class Pantry
|
6
|
+
# This is the user-provided filepath name that parse will use to
|
7
|
+
# generate an array.
|
4
8
|
attr_accessor :filepath
|
9
|
+
# This is where the pantry ingredients array will be stored.
|
5
10
|
attr_reader :list
|
6
11
|
|
12
|
+
# This method creates a new Pantry object that takes the filepath
|
13
|
+
# of a text file, and is described by an array of the contents.
|
7
14
|
def initialize(filepath)
|
8
15
|
@filepath = filepath
|
9
16
|
@list = []
|
10
17
|
end
|
11
18
|
|
19
|
+
# This method opens the filepath given and produces a
|
20
|
+
# one-dimensional array called list.
|
12
21
|
def parse
|
13
22
|
CSV.foreach(self.filepath) {|row| @list << row}
|
14
23
|
@list.flatten!
|
@@ -1,13 +1,22 @@
|
|
1
|
-
class
|
1
|
+
# This class is responsible for funneling the data pulled from Yummly
|
2
|
+
# and processing it into a hash that Reverser can process.
|
3
|
+
class RecipeList
|
4
|
+
# This is what we get from Yummly.
|
2
5
|
attr_accessor :result
|
6
|
+
# This is what we'll be generating from Yummly data.
|
3
7
|
attr_reader :recipehash
|
4
8
|
|
9
|
+
# This method defines a new RecipeList, which is receives a data object
|
10
|
+
# generated from the Yummly API, and produces a hash with recipe names
|
11
|
+
# for the keys, and an array of ingredients for the values.
|
5
12
|
def initialize(result)
|
6
13
|
@result = result
|
7
14
|
@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
15
|
end
|
10
16
|
|
17
|
+
# This method builds the working hash from Yummly data, and
|
18
|
+
# initializes the last entry in the value array with a score
|
19
|
+
# of 0.
|
11
20
|
def listbuilder
|
12
21
|
recipes = result.collect {|recipe| recipe.name}
|
13
22
|
elements = result.collect {|recipe| recipe.ingredients}
|
@@ -1,14 +1,27 @@
|
|
1
|
+
# This class is responsible for comparing the list generated from Pantry
|
2
|
+
# and the hash generated from RecipeList, and delivering the recipes with
|
3
|
+
# the maximum number of ingredient matches.
|
4
|
+
|
1
5
|
class Reverser
|
2
|
-
|
3
|
-
|
6
|
+
|
7
|
+
# This is the array of ingredients that we receive from performing Pantry.parse.
|
8
|
+
attr_accessor :pantrylist
|
9
|
+
# This is the hash of recipes/ingredients that we processed (via Yummly) with RecipeList.
|
10
|
+
attr_accessor :tee
|
11
|
+
# This is a hash of recipes, sorted by score, in the form of an Array.
|
4
12
|
attr_reader :eat
|
5
13
|
|
14
|
+
# This creates a new Reverser object, which is described by a sorted hash in the form
|
15
|
+
# of an Array of Arrays.
|
6
16
|
def initialize(pantrylist, tee)
|
7
17
|
@pantrylist = pantrylist
|
8
18
|
@tee = tee
|
9
19
|
@eat = Hash.new
|
10
20
|
end
|
11
21
|
|
22
|
+
# This method is responsible for first, comparing our ingredients with
|
23
|
+
# the recipes' ingredients, and then updating the recipe hash with
|
24
|
+
# the corresponding match scores, and then sorting the hash by that score.
|
12
25
|
def reverse
|
13
26
|
@tee.each do |k,v|
|
14
27
|
templist = v.join(" ")
|
@@ -19,6 +32,8 @@ class Reverser
|
|
19
32
|
@eat = @tee.sort_by{|k,v| v[-1]}
|
20
33
|
end
|
21
34
|
|
35
|
+
# This method concludes the Execute method, and churns out the top 2
|
36
|
+
# recipe picks for the end user to pick from.
|
22
37
|
def choose
|
23
38
|
puts "Your best options are #{@eat[-1][0]}, and #{@eat[-2][0]}. You already have #{@eat[-1][-1][-1]}, and #{@eat[-2][-1][-1]} ingredients for each of those, respectively."
|
24
39
|
puts " "
|
data/lib/tee_reverser/version.rb
CHANGED
data/lib/tee_reverser.rb
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
require 'yummly'
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
# TeeReverser: (Tee => Eet...eat!)
|
3
|
+
# Author:: Steven Xu (mailto: steven.b.xu at gmail.com)
|
4
|
+
# Copyright:: Copyright (c) 2013, Steven Xu
|
5
|
+
# License:: Distributes under the same terms as Ruby
|
5
6
|
#
|
6
7
|
# TeeReverser is a gem that assists in the complex decision making
|
7
|
-
# process that is
|
8
|
-
# that you own in your very own pantry,
|
8
|
+
# process that is deciding what to cook. Given a text file with a list of ingredients
|
9
|
+
# that you own in your very own pantry, as well as a desired dish that you wish
|
9
10
|
# to make, TeeReverser returns two recipes from Yummly.com that
|
10
|
-
#
|
11
|
-
#
|
12
|
-
|
11
|
+
# have the best match with your pantry -- thereby saving you an average of
|
12
|
+
# four seconds of decision making every time!
|
13
|
+
#
|
13
14
|
# To run, require 'tee_reverser' and enter TeeReverser.execute in the command
|
14
|
-
# line.
|
15
|
+
# line. TeeReverser requires the Yummly and CSV gems to run.
|
15
16
|
|
16
17
|
module TeeReverser
|
17
18
|
require 'tee_reverser/reverser.rb'
|
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.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -25,7 +25,7 @@ files:
|
|
25
25
|
- lib/tee_reverser/version.rb
|
26
26
|
homepage: http://rubygems.org/gems/tee_reverser
|
27
27
|
licenses:
|
28
|
-
-
|
28
|
+
- Distributes under the same terms as ruby.
|
29
29
|
post_install_message:
|
30
30
|
rdoc_options: []
|
31
31
|
require_paths:
|
@@ -42,10 +42,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
42
42
|
- - ! '>='
|
43
43
|
- !ruby/object:Gem::Version
|
44
44
|
version: '0'
|
45
|
-
requirements:
|
45
|
+
requirements:
|
46
|
+
- gems Yummly and CSV
|
46
47
|
rubyforge_project:
|
47
48
|
rubygems_version: 1.8.24
|
48
49
|
signing_key:
|
49
50
|
specification_version: 3
|
50
|
-
summary:
|
51
|
+
summary: Choosing a recipe, made...simpler?
|
51
52
|
test_files: []
|