lettuce 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.
@@ -0,0 +1,30 @@
1
+ require 'lettuce'
2
+
3
+ describe Lettuce::HRecipe do
4
+ before(:all) do
5
+ @file = open(File.join(File.dirname(__FILE__), "fixtures/asparagus.html"))
6
+ @document = Nokogiri::HTML(@file)
7
+
8
+ @url = "http://www.foodnetwork.com/recipes/tyler-florence/roasted-asparagus-recipe/index.html"
9
+ end
10
+
11
+ it 'should be able to parse this recipe' do
12
+ Lettuce::HRecipe.can_parse?(@document, @url)
13
+ end
14
+
15
+ it 'should be called Roasted Asparagus' do
16
+ recipe = Lettuce::HRecipe.new(@document, @url)
17
+
18
+ recipe.title.should == "Roasted Asparagus"
19
+ end
20
+
21
+ it 'should return only 6 ingredients' do
22
+ recipe = Lettuce::HRecipe.new(@document, @url)
23
+ recipe.ingredients.size.should == 5
24
+ end
25
+
26
+ it 'should have a valid photo url' do
27
+ recipe = Lettuce::HRecipe.new(@document, @url)
28
+ recipe.photo.should == "http://img.foodnetwork.com/FOOD/2009/01/13/vday_roastedasparagus4854_s4x3_med.jpg"
29
+ end
30
+ end
@@ -0,0 +1,44 @@
1
+ require 'lettuce'
2
+ require 'open-uri'
3
+ require 'uri'
4
+
5
+ describe Lettuce do
6
+ before(:all) do
7
+ module OpenURI
8
+ module OpenRead
9
+ def open(*rest, &block)
10
+ case self.to_s
11
+ when "http://www.foodnetwork.com/recipes/tyler-florence/roasted-asparagus-recipe/index.html"
12
+ url = File.join(File.dirname(__FILE__), "fixtures/asparagus.html")
13
+ when "http://allrecipes.com/Recipe/Pineapple-Sweet-Rolls/Detail.aspx"
14
+ url = File.join(File.dirname(__FILE__), "fixtures/pineapple_rolls.html")
15
+ else
16
+ url = File.join(File.dirname(__FILE__), "fixtures/default.html")
17
+ end
18
+
19
+ open_uri_original_open(url, *rest, &block)
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ it 'should return nil if no recipes are found' do
26
+ Lettuce.parse("http://tomrudick.com").should == nil
27
+ end
28
+
29
+ it 'should return nil if it gets a bad url' do
30
+ Lettuce.parse("this is not a URL I don't even").should == nil
31
+ end
32
+
33
+ it 'should return a recipe object called Roasted Asparagus' do
34
+ recipe = Lettuce.parse("http://www.foodnetwork.com/recipes/tyler-florence/roasted-asparagus-recipe/index.html")
35
+
36
+ recipe.title.should == "Roasted Asparagus"
37
+ end
38
+
39
+ it 'should return a recipe object called Pineapple Sweet Rolls' do
40
+ recipe = Lettuce.parse("http://allrecipes.com/Recipe/Pineapple-Sweet-Rolls/Detail.aspx")
41
+
42
+ recipe.title.should == "Pineapple Sweet Rolls"
43
+ end
44
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lettuce
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,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-08 00:00:00.000000000Z
12
+ date: 2012-02-27 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
16
- requirement: &2153679760 !ruby/object:Gem::Requirement
16
+ requirement: &2157384140 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2153679760
24
+ version_requirements: *2157384140
25
25
  description: A Ruby hRecipe Microformat parser using Nokogiri
26
26
  email:
27
27
  - tmrudick@gmail.com
@@ -34,12 +34,15 @@ files:
34
34
  - Rakefile
35
35
  - lettuce.gemspec
36
36
  - lib/lettuce.rb
37
- - lib/lettuce/hingredient.rb
38
- - lib/lettuce/hrecipe.rb
37
+ - lib/lettuce/hrecipe/all_recipes.rb
38
+ - lib/lettuce/hrecipe/hrecipe.rb
39
39
  - lib/lettuce/version.rb
40
- - test/fixtures/asparagus.html
41
- - test/helper.rb
42
- - test/test_lettuce.rb
40
+ - spec/all_recipes_spec.rb
41
+ - spec/fixtures/asparagus.html
42
+ - spec/fixtures/default.html
43
+ - spec/fixtures/pineapple_rolls.html
44
+ - spec/hrecipe_spec.rb
45
+ - spec/lettuce_spec.rb
43
46
  homepage: http://github.com/tmrudick/lettuce
44
47
  licenses: []
45
48
  post_install_message:
@@ -65,6 +68,9 @@ signing_key:
65
68
  specification_version: 3
66
69
  summary: A Ruby hRecipe Microformat parser
67
70
  test_files:
68
- - test/fixtures/asparagus.html
69
- - test/helper.rb
70
- - test/test_lettuce.rb
71
+ - spec/all_recipes_spec.rb
72
+ - spec/fixtures/asparagus.html
73
+ - spec/fixtures/default.html
74
+ - spec/fixtures/pineapple_rolls.html
75
+ - spec/hrecipe_spec.rb
76
+ - spec/lettuce_spec.rb
@@ -1,3 +0,0 @@
1
- class HIngredient
2
- attr_accessor :text, :value, :type
3
- end
@@ -1,55 +0,0 @@
1
- require 'lettuce/hingredient'
2
-
3
- class HRecipe
4
-
5
- attr_accessor :fn, :ingredients
6
-
7
- def initialize(doc, url)
8
- @ndoc = doc
9
- @url = url # May be eventually used for page wrapping
10
- @valid = true
11
- parse
12
- end
13
-
14
- def is_valid?
15
- @valid
16
- end
17
-
18
- # Parse photo
19
- def photo
20
- photo_element = @ndoc.css('.photo')
21
-
22
- return nil if photo_element.size == 0
23
-
24
- return photo_element[0]['src']
25
- end
26
-
27
- private
28
- def parse
29
- # Parse all required fields (fn, ingredients) and lazy load everything else
30
-
31
- # Parse name
32
- fn = @ndoc.css('.fn')
33
- if fn.size > 1 then
34
- @valid = false
35
- return
36
- end
37
-
38
- @fn = fn[0].content
39
-
40
- # Parse ingredient list
41
- ingredients = @ndoc.css('.ingredient')
42
- if ingredients.size == 0 then
43
- @valid = false
44
- return
45
- end
46
-
47
- # TODO: Also parse type and value
48
- @ingredients = []
49
- ingredients.each do |i|
50
- ingredient = HIngredient.new
51
- ingredient.text = i.content
52
- @ingredients.push ingredient
53
- end
54
- end
55
- end
@@ -1,3 +0,0 @@
1
- def html_test_filename(filename)
2
- File.join(File.dirname(__FILE__), 'fixtures', filename)
3
- end
@@ -1,27 +0,0 @@
1
- require 'test/unit'
2
- require 'lettuce'
3
- require File.join(File.dirname(File.absolute_path(__FILE__)),'helper')
4
-
5
- class LettuceTest < Test::Unit::TestCase
6
-
7
- def test_bad_url
8
- assert_equal [], Lettuce.parse_url("this is not a url")
9
- end
10
-
11
- def test_no_url
12
- assert_equal [], Lettuce.parse_url(nil)
13
- end
14
-
15
- def test_url_with_no_hrecipe
16
- assert_equal [], Lettuce.parse_url("http://www.tomrudick.com")
17
- end
18
-
19
- def test_foodtv
20
- recipes = Lettuce.parse_url(html_test_filename("asparagus.html"))
21
-
22
- assert_equal 1, recipes.size
23
- assert_equal "Roasted Asparagus", recipes[0].fn
24
- assert_equal 5, recipes[0].ingredients.size
25
- assert_equal "http://img.foodnetwork.com/FOOD/2009/01/13/vday_roastedasparagus4854_s4x3_med.jpg", recipes[0].photo
26
- end
27
- end