tee_reverser 0.0.1 → 0.0.2

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.rb CHANGED
@@ -1,43 +1,35 @@
1
1
  require 'yummly'
2
2
  require './tee_reverser/reverser.rb'
3
- require './tee_reverser/recipelist.rb'
3
+ require './tee_reverser/recipe_list.rb'
4
4
  require './tee_reverser/pantry.rb'
5
5
 
6
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
-
7
+ Yummly.configure do |config|
8
+ config.app_id = "bddcbcff"
9
+ config.app_key = "9245c33f2cc6d6bedb65715d3fb66c61"
10
+ end
11
+ puts "Please give me the filepath of your pantry list, in .txt format."
12
+ puts "Your list will ideally have any each ingredient you wish to itemize in its own line."
13
+ location = gets.chomp
14
+ #ensures only proper objects get loaded
15
+ until /.txt/.match(location.to_str) && File.exists?("#{location}") do
16
+ puts "Please give me a valid filepath and name. File must exist and be in *.txt format."
17
+ location = gets.chomp
18
+ end
19
+ goods = Pantry.new(location)
20
+ goods.parse
21
+ puts "What kind of dish would you like to make?"
22
+ wishlist = gets.chomp
23
+ puts " "
24
+ puts "-------------------C O N N E C T I N G---------------------"
25
+ puts " "
26
+ query = Yummly.search("#{wishlist}")
27
+ meal = RecipeList.new(query)
28
+ meal.listbuilder
29
+ puts " "
30
+ puts "---------------------T H I N K I N G-----------------------"
31
+ puts " "
32
+ decisions = Reverser.new(goods.list, meal.recipehash)
33
+ decisions.reverse
34
+ decisions.choose
43
35
  end
@@ -10,7 +10,7 @@ class Pantry #establishes user ingredients
10
10
  end
11
11
 
12
12
  def parse
13
- CSV.foreach(self.filepath) {|row| list << row}
14
- list.flatten!
13
+ CSV.foreach(self.filepath) {|row| @list << row}
14
+ @list.flatten!
15
15
  end
16
- end
16
+ end
@@ -12,8 +12,8 @@ class RecipeList #funnels Yummly results into workable hash
12
12
  recipes = result.collect {|recipe| recipe.name}
13
13
  elements = result.collect {|recipe| recipe.ingredients}
14
14
  for num in 0..recipes.size-1
15
- recipehash[recipes[num]]=elements[num]
15
+ @recipehash[recipes[num]]=elements[num]
16
16
  end
17
- recipehash.each {|k,v| v<<0}
17
+ @recipehash.each {|k,v| v<<0}
18
18
  end
19
19
  end
@@ -9,17 +9,27 @@ class Reverser
9
9
  @eat = Hash.new
10
10
  end
11
11
 
12
- def reverse
13
- tee.each do |k,v|
12
+ def reverse
13
+ @tee.each do |k,v|
14
14
  templist = v.join(" ")
15
- for num in 0..pantrylist.size-1
16
- tee[k][-1]+=1 if /#{pantrylist[num]}/.match(templist)
15
+ for num in 0..@pantrylist.size-1
16
+ @tee[k][-1]+=1 if /#{@pantrylist[num]}/.match(templist)
17
17
  end
18
- puts eat.is_a? Hash
19
18
  end
20
- puts tee
21
- eat = tee
22
- puts eat
19
+ @eat = @tee.sort_by{|k,v| v[-1]}
23
20
  end
24
21
 
22
+ def choose
23
+ 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
+ puts " "
25
+ ingredients1 = @eat[-1][-1]
26
+ ingredients1.pop
27
+ ingredients2 = @eat [-2][-1]
28
+ ingredients2.pop
29
+ puts "The ingredients for #{@eat[-1][0]} are: #{ingredients1.join(", ")}."
30
+ puts " "
31
+ puts "The ingredients for #{@eat[-2][0]} are: #{ingredients2.join(", ")}."
32
+ puts " "
33
+ puts "Bon appetit!"
34
+ end
25
35
  end
@@ -0,0 +1,6 @@
1
+ # encoding: UTF-8
2
+ # Copyright © 2013, stevenbxu
3
+
4
+ module TeeReverser
5
+ VERSION = "0.0.2"
6
+ 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.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-08 00:00:00.000000000 Z
12
+ date: 2013-12-09 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Determines optimal recipe given pantry contents. Powered by Yummly.
15
15
  email: steven.b.xu@gmail.com
@@ -19,8 +19,9 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - lib/tee_reverser.rb
21
21
  - lib/tee_reverser/pantry.rb
22
- - lib/tee_reverser/recipelist.rb
22
+ - lib/tee_reverser/recipe_list.rb
23
23
  - lib/tee_reverser/reverser.rb
24
+ - lib/tee_reverser/version.rb
24
25
  homepage: http://rubygems.org/gems/tee_reverser
25
26
  licenses:
26
27
  - ! '?'
@@ -45,5 +46,5 @@ rubyforge_project:
45
46
  rubygems_version: 1.8.24
46
47
  signing_key:
47
48
  specification_version: 3
48
- summary: Basic functions defined
49
+ summary: Basic functions finished
49
50
  test_files: []