tychus 0.0.4 → 0.0.5
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.
- checksums.yaml +4 -4
- data/lib/tychus/parsers/allrecipes_parser.rb +2 -1
- data/lib/tychus/parsers/base.rb +4 -4
- data/lib/tychus/parsers/kraft_recipes_parser.rb +17 -17
- data/lib/tychus/parsers/schema_org_parser.rb +24 -23
- data/lib/tychus/version.rb +1 -1
- metadata +1 -2
- data/lib/tychus/utilities/url_parser.rb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bc9018fe36889fe35e6f7c628bca5e4920b5fb4
|
4
|
+
data.tar.gz: a6af0d410b9c61d59c618d447ff53df239b8ea30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9019b38648df1eb14df472991eaca4e8f349b6456a7c78d4b4458cd713e03d0ee61c8a24904dea1e60c8159de56c04799808f03b8c98c4d2089e480a1cba40a9
|
7
|
+
data.tar.gz: 714686e496f584676dd25677287eec0fc63973dc87ea566a49685068ae1251660385cb6b0f2abf9d13459799766050ebcd3e2878248d24e0662794c1519df75e
|
data/lib/tychus/parsers/base.rb
CHANGED
@@ -35,6 +35,10 @@ module Parsers
|
|
35
35
|
@recipe_doc = @doc.css(root_doc)
|
36
36
|
end
|
37
37
|
|
38
|
+
def clean_instructions(obj)
|
39
|
+
obj
|
40
|
+
end
|
41
|
+
|
38
42
|
def parse
|
39
43
|
recipe_attributes.each do |attr|
|
40
44
|
property_value = __send__("parse_#{attr}")
|
@@ -47,10 +51,6 @@ module Parsers
|
|
47
51
|
self.class.recipe_attributes
|
48
52
|
end
|
49
53
|
|
50
|
-
def clean_instructions(obj)
|
51
|
-
obj
|
52
|
-
end
|
53
|
-
|
54
54
|
def Value(obj)
|
55
55
|
case obj
|
56
56
|
when NullObject then nil
|
@@ -13,6 +13,23 @@ module Parsers
|
|
13
13
|
doc.css('meta[name="description"]').first.attr('content')
|
14
14
|
end
|
15
15
|
|
16
|
+
def parse_ingredients
|
17
|
+
# "1 lb.\r\n\t\t\t\t\t\t\t\t boneless skinless chicken breasts, cut into 1-1/2-inch pieces", "2 cups\r\n\t\t\t\t\t\t\t\t fresh pineapple chunks (1-1/2 inch)", "1 \r\n\t\t\t\t\t\t\t\t each red and green pepper, cut into 1-1/2-inch pieces", "1/2 cup\r\n\t\t\t\t\t\t\t\t KRAFT Original Barbecue Sauce", "3 Tbsp.\r\n\t\t\t\t\t\t\t\t frozen orange juice concentrate, thawed"
|
18
|
+
recipe_doc
|
19
|
+
.css('[itemprop="ingredients"]')
|
20
|
+
.map do|ingredient_node|
|
21
|
+
ingredient_node
|
22
|
+
.element_children
|
23
|
+
.map do |node| node.content
|
24
|
+
.lstrip
|
25
|
+
.rstrip
|
26
|
+
.squeeze(" ")
|
27
|
+
.gsub(/(\r|\n|\t)/,'')
|
28
|
+
end.join(" ")
|
29
|
+
end.reject(&:blank?)
|
30
|
+
end
|
31
|
+
|
32
|
+
|
16
33
|
def parse_name
|
17
34
|
# "\r\n\tSweet BBQ Chicken Kabobs\r\n\t"
|
18
35
|
result = super
|
@@ -31,23 +48,6 @@ module Parsers
|
|
31
48
|
end.flatten.reject(&:blank?)
|
32
49
|
end
|
33
50
|
|
34
|
-
def parse_ingredients
|
35
|
-
# NOT FIRST
|
36
|
-
# "1 lb.\r\n\t\t\t\t\t\t\t\t boneless skinless chicken breasts, cut into 1-1/2-inch pieces", "2 cups\r\n\t\t\t\t\t\t\t\t fresh pineapple chunks (1-1/2 inch)", "1 \r\n\t\t\t\t\t\t\t\t each red and green pepper, cut into 1-1/2-inch pieces", "1/2 cup\r\n\t\t\t\t\t\t\t\t KRAFT Original Barbecue Sauce", "3 Tbsp.\r\n\t\t\t\t\t\t\t\t frozen orange juice concentrate, thawed"
|
37
|
-
recipe_doc
|
38
|
-
.css('[itemprop="ingredients"]')
|
39
|
-
.map do|ingredient_node|
|
40
|
-
ingredient_node
|
41
|
-
.element_children
|
42
|
-
.map do |node| node.content
|
43
|
-
.lstrip
|
44
|
-
.rstrip
|
45
|
-
.squeeze(" ")
|
46
|
-
.gsub(/(\r|\n|\t)/,'')
|
47
|
-
end.join(" ")
|
48
|
-
end.reject(&:blank?)
|
49
|
-
end
|
50
|
-
|
51
51
|
end
|
52
52
|
|
53
53
|
end
|
@@ -14,6 +14,10 @@ module Parsers
|
|
14
14
|
strip_video_object_microformat
|
15
15
|
end
|
16
16
|
|
17
|
+
def itemprop_node_for(property)
|
18
|
+
recipe_doc.css("[itemprop='#{property}']").first || NullObject.new
|
19
|
+
end
|
20
|
+
|
17
21
|
def parse_author
|
18
22
|
itemprop_node_for(:author).content
|
19
23
|
end
|
@@ -31,7 +35,7 @@ module Parsers
|
|
31
35
|
# reject headers such as "Directions" and divs such as .categories for Foodnetwork recipes
|
32
36
|
reject_regex = /^(h.|div)$/
|
33
37
|
|
34
|
-
|
38
|
+
itemprop_node_for(:recipeInstructions)
|
35
39
|
.element_children
|
36
40
|
.reject { |node| node.name =~ reject_regex }
|
37
41
|
.map do |node|
|
@@ -39,11 +43,7 @@ module Parsers
|
|
39
43
|
.squeeze(" ")
|
40
44
|
.rstrip
|
41
45
|
.split("\r\n\s\r\n\s")
|
42
|
-
end.flatten.reject(&:blank?)
|
43
|
-
end
|
44
|
-
|
45
|
-
def parse_name
|
46
|
-
itemprop_node_for(:name).content
|
46
|
+
end.flatten.reject(&:blank?)
|
47
47
|
end
|
48
48
|
|
49
49
|
def parse_cook_time
|
@@ -51,6 +51,20 @@ module Parsers
|
|
51
51
|
parse_duration(itemprop_node_for(:cookTime))
|
52
52
|
end
|
53
53
|
|
54
|
+
def parse_duration(node)
|
55
|
+
# Allrecipes - 'time' element
|
56
|
+
# Foodnetwork - 'meta' element (std according to
|
57
|
+
# Schema.org/Recipe)
|
58
|
+
case node.name
|
59
|
+
when "meta", "span"
|
60
|
+
node.attr('content')
|
61
|
+
when "time"
|
62
|
+
node.attr('datetime')
|
63
|
+
else
|
64
|
+
NullObject.new
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
54
68
|
def parse_image
|
55
69
|
itemprop_node_for(:image).attr('src')
|
56
70
|
end
|
@@ -67,22 +81,12 @@ module Parsers
|
|
67
81
|
end.reject(&:blank?)
|
68
82
|
end
|
69
83
|
|
70
|
-
def
|
71
|
-
|
84
|
+
def parse_name
|
85
|
+
itemprop_node_for(:name).content
|
72
86
|
end
|
73
87
|
|
74
|
-
def
|
75
|
-
|
76
|
-
# Foodnetwork - 'meta' element (std according to
|
77
|
-
# Schema.org/Recipe)
|
78
|
-
case node.name
|
79
|
-
when "meta", "span"
|
80
|
-
node.attr('content')
|
81
|
-
when "time"
|
82
|
-
node.attr('datetime')
|
83
|
-
else
|
84
|
-
NullObject.new
|
85
|
-
end
|
88
|
+
def parse_prep_time
|
89
|
+
parse_duration(itemprop_node_for(:prepTime))
|
86
90
|
end
|
87
91
|
|
88
92
|
def parse_recipe_yield
|
@@ -102,9 +106,6 @@ module Parsers
|
|
102
106
|
recipe_doc.css(video_object_doc).remove
|
103
107
|
end
|
104
108
|
|
105
|
-
def itemprop_node_for(property)
|
106
|
-
recipe_doc.css("[itemprop='#{property}']").first || NullObject.new
|
107
|
-
end
|
108
109
|
end
|
109
110
|
|
110
111
|
end
|
data/lib/tychus/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tychus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wayne Yang
|
@@ -172,7 +172,6 @@ files:
|
|
172
172
|
- lib/tychus/parsers/kraft_recipes_parser.rb
|
173
173
|
- lib/tychus/parsers/schema_org_parser.rb
|
174
174
|
- lib/tychus/uri_resolver.rb
|
175
|
-
- lib/tychus/utilities/url_parser.rb
|
176
175
|
- lib/tychus/version.rb
|
177
176
|
- questions.md
|
178
177
|
- spec/fixtures/allrecipes.html
|
File without changes
|