allrecipes 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -10
- data/lib/allrecipes.rb +1 -0
- data/lib/allrecipes/ingredients_parser.rb +50 -0
- data/lib/allrecipes/recipe_parser.rb +1 -37
- data/lib/allrecipes/version.rb +1 -1
- data/spec/ingredient_parser_spec.rb +26 -0
- data/spec/recipe_parser_spec.rb +2 -15
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a76845bcdebb9e51e1311fb837910787b0c01311
|
4
|
+
data.tar.gz: e5637481662634979738a7feb2ea3f8c76dc5aa5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7c0db453b9dab2927dd40147c4c3cc8dc2dd57a037400c8dfa63aa6e2a388bcb0496b0c9fa2708d435bd9c4b23cc81f113e5a91f46ff467b367abf365926c93
|
7
|
+
data.tar.gz: ec9fa16ffc9c391ff1facb8b130537431ad993793ede0e1b745eb4220ba0e57fce154fdef9997acd976f96da4a7b46d56b89476600c75538acc2417d5cc7af90
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# The Allrecipes Ruby Gem
|
1
|
+
# The <a href="http://allrecipes.com" target="_blank">Allrecipes</a> Ruby Gem
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/allrecipes.svg)](http://badge.fury.io/rb/allrecipes)
|
3
3
|
[![Build Status](https://travis-ci.org/shivamd/allrecipes.svg?branch=master)](https://travis-ci.org/shivamd/allrecipes)
|
4
4
|
[![Dependency Status](https://gemnasium.com/shivamd/allrecipes.svg)](https://gemnasium.com/shivamd/allrecipes)
|
@@ -152,7 +152,15 @@ If mentioned outside of this scope, will resort to default(relevance).
|
|
152
152
|
```ruby
|
153
153
|
recipes.ingredient("apples", { sort_by: "rating", page: 3 })
|
154
154
|
```
|
155
|
+
**Get recipe from url**
|
156
|
+
```ruby
|
157
|
+
recipes.recipe_url("http://allrecipes.com/Recipe/Worlds-Best-Lasagna")
|
158
|
+
```
|
155
159
|
|
160
|
+
**Get recipes from a page which has a collection of recipes**
|
161
|
+
```ruby
|
162
|
+
recipes.page_url("http://allrecipes.com/recipes?Page=7")
|
163
|
+
```
|
156
164
|
|
157
165
|
**Sample response**
|
158
166
|
```ruby
|
@@ -175,18 +183,21 @@ recipes.ingredient("apples", { sort_by: "rating", page: 3 })
|
|
175
183
|
"Bring a large pot of lightly salted water to a boil"
|
176
184
|
}
|
177
185
|
]
|
186
|
+
:rating => 5.0, #number between 0 and 5, rounded to the nearest .5
|
187
|
+
:prep_time => 90, #in minutes
|
188
|
+
:cook_time => 60 #in minutes
|
178
189
|
}
|
179
190
|
]
|
180
191
|
```
|
181
192
|
|
182
193
|
## Todo
|
183
194
|
|
184
|
-
1.
|
185
|
-
2.
|
186
|
-
3.
|
187
|
-
4.
|
188
|
-
5. Add
|
189
|
-
6.
|
190
|
-
7. Able to
|
191
|
-
|
192
|
-
|
195
|
+
1. Option for selecting what keys to return.
|
196
|
+
2. Complex search with queries such as multiple ingredients, course, time etc.
|
197
|
+
3. Faster test suite
|
198
|
+
4. Move ingredients parsing into its own class.
|
199
|
+
5. Add nutrional info to results.
|
200
|
+
6. Add user photos for recipe to results
|
201
|
+
7. Able to get popular recipes of the day.
|
202
|
+
|
203
|
+
|
data/lib/allrecipes.rb
CHANGED
@@ -0,0 +1,50 @@
|
|
1
|
+
class IngredientsParser
|
2
|
+
def initialize(page)
|
3
|
+
@page = page
|
4
|
+
@ingredients = []
|
5
|
+
parse_ingredients
|
6
|
+
end
|
7
|
+
|
8
|
+
def parse_ingredients
|
9
|
+
ingredients_list.each do |ingredient|
|
10
|
+
amount = amount(ingredient)
|
11
|
+
ingredient_name= ingredient_name(ingredient)
|
12
|
+
add_ingredient_to_list(amount, ingredient_name)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def ingredients_list
|
17
|
+
@page.search(ingredients_class)
|
18
|
+
end
|
19
|
+
|
20
|
+
def ingredients_class
|
21
|
+
".fl-ing"
|
22
|
+
end
|
23
|
+
|
24
|
+
def add_ingredient_to_list(amount, ingredient_name)
|
25
|
+
if amount && ingredient_name #some recipes have empty ingredients
|
26
|
+
quantity,unit = amount.text.split(" ")
|
27
|
+
@ingredients << { quantity: quantity.to_f, unit: unit, name: ingredient_name.text }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def amount(ingredient)
|
32
|
+
ingredient.search(ingredient_amount_class).children[0]
|
33
|
+
end
|
34
|
+
|
35
|
+
def ingredient_amount_class
|
36
|
+
".ingredient-amount"
|
37
|
+
end
|
38
|
+
|
39
|
+
def ingredient_name(ingredient)
|
40
|
+
ingredient.search(ingredient_name_class).children[0]
|
41
|
+
end
|
42
|
+
|
43
|
+
def ingredient_name_class
|
44
|
+
".ingredient-name"
|
45
|
+
end
|
46
|
+
|
47
|
+
def ingredients
|
48
|
+
@ingredients
|
49
|
+
end
|
50
|
+
end
|
@@ -3,7 +3,6 @@ class RecipeParser
|
|
3
3
|
def initialize(page)
|
4
4
|
@page = request_page(page)
|
5
5
|
@directions = []
|
6
|
-
@ingredients = []
|
7
6
|
get_ingredients
|
8
7
|
get_directions
|
9
8
|
end
|
@@ -94,43 +93,8 @@ class RecipeParser
|
|
94
93
|
end
|
95
94
|
end
|
96
95
|
|
97
|
-
def ingredients_list
|
98
|
-
@page.search(ingredients_class)
|
99
|
-
end
|
100
|
-
|
101
|
-
def ingredients_class
|
102
|
-
".fl-ing"
|
103
|
-
end
|
104
|
-
|
105
96
|
def get_ingredients
|
106
|
-
|
107
|
-
amount = amount(ingredient)
|
108
|
-
ingredient_name= ingredient_name(ingredient)
|
109
|
-
add_ingredient_to_list(amount, ingredient_name)
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def add_ingredient_to_list(amount, ingredient_name)
|
114
|
-
if amount && ingredient_name #some recipes have empty ingredients
|
115
|
-
quantity,unit = amount.text.split(" ")
|
116
|
-
@ingredients << { "quantity" => quantity.to_f, "unit"=>unit, "name" => ingredient_name.text }
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
def amount(ingredient)
|
121
|
-
ingredient.search(ingredient_amount_class).children[0]
|
122
|
-
end
|
123
|
-
|
124
|
-
def ingredient_amount_class
|
125
|
-
".ingredient-amount"
|
126
|
-
end
|
127
|
-
|
128
|
-
def ingredient_name(ingredient)
|
129
|
-
ingredient.search(ingredient_name_class).children[0]
|
130
|
-
end
|
131
|
-
|
132
|
-
def ingredient_name_class
|
133
|
-
".ingredient-name"
|
97
|
+
@ingredients = IngredientsParser.new(@page).ingredients
|
134
98
|
end
|
135
99
|
|
136
100
|
def recipe
|
data/lib/allrecipes/version.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe IngredientsParser do
|
3
|
+
before do
|
4
|
+
VCR.use_cassette "ingredients_parser" do
|
5
|
+
url = "http://allrecipes.com/Recipe/Worlds-Best-Lasagna/"
|
6
|
+
page = Mechanize.new.get(url)
|
7
|
+
@ing_parser = IngredientsParser.new(page)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should have the right amount of ingredients" do
|
12
|
+
expect(@ing_parser.ingredients.count).to eq 21
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should have the correct quantity" do
|
16
|
+
expect(@ing_parser.ingredients.first[:quantity]).to eq 1
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should have the correct unit" do
|
20
|
+
expect(@ing_parser.ingredients.first[:unit]).to eq "pound"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should have the correct ingredient name" do
|
24
|
+
expect(@ing_parser.ingredients.first[:name]).to eq "sweet Italian sausage"
|
25
|
+
end
|
26
|
+
end
|
data/spec/recipe_parser_spec.rb
CHANGED
@@ -31,21 +31,8 @@ describe RecipeParser do
|
|
31
31
|
expect(@recipe[:cook_time]).to eq 150
|
32
32
|
end
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
it "should have the right amount of ingredients" do
|
37
|
-
expect(@recipe[:ingredients].count).to eq 21
|
38
|
-
end
|
39
|
-
it "should have the right quantity" do
|
40
|
-
expect(@recipe[:ingredients].first["quantity"]).to eq 1
|
41
|
-
end
|
42
|
-
it "should have the right unit" do
|
43
|
-
expect(@recipe[:ingredients].first["unit"]).to eq "pound"
|
44
|
-
end
|
45
|
-
it "should have the right name" do
|
46
|
-
expect(@recipe[:ingredients].first["name"]).to eq "sweet Italian sausage"
|
47
|
-
end
|
48
|
-
|
34
|
+
it "should have the right amount of ingredients" do
|
35
|
+
expect(@recipe[:ingredients].count).to eq 21
|
49
36
|
end
|
50
37
|
|
51
38
|
it "should have the right amount of directions" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: allrecipes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- shivamd
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mechanize
|
@@ -124,6 +124,7 @@ files:
|
|
124
124
|
- Rakefile
|
125
125
|
- allrecipes.gemspec
|
126
126
|
- lib/allrecipes.rb
|
127
|
+
- lib/allrecipes/ingredients_parser.rb
|
127
128
|
- lib/allrecipes/main.rb
|
128
129
|
- lib/allrecipes/page_parser.rb
|
129
130
|
- lib/allrecipes/recipe_parser.rb
|
@@ -131,6 +132,7 @@ files:
|
|
131
132
|
- lib/allrecipes/version.rb
|
132
133
|
- spec/allrecipes_spec.rb
|
133
134
|
- spec/fixtures/recipe.json
|
135
|
+
- spec/ingredient_parser_spec.rb
|
134
136
|
- spec/page_parser_spec.rb
|
135
137
|
- spec/recipe_filter_spec.rb
|
136
138
|
- spec/recipe_parser_spec.rb
|
@@ -162,6 +164,7 @@ summary: A Ruby wrapper for allrecipes.com
|
|
162
164
|
test_files:
|
163
165
|
- spec/allrecipes_spec.rb
|
164
166
|
- spec/fixtures/recipe.json
|
167
|
+
- spec/ingredient_parser_spec.rb
|
165
168
|
- spec/page_parser_spec.rb
|
166
169
|
- spec/recipe_filter_spec.rb
|
167
170
|
- spec/recipe_parser_spec.rb
|