Class: Lettuce::Recipe
- Inherits:
-
Object
- Object
- Lettuce::Recipe
- Defined in:
- lib/lettuce/recipe.rb
Direct Known Subclasses
Class Method Summary collapse
- .can_parse?(doc, url) ⇒ Boolean
- .parse(doc, url) ⇒ Object
- .parse_all(doc, url) ⇒ Object
- .root(root) ⇒ Object
Instance Method Summary collapse
- #author(selector = '.author') ⇒ Object
- #duration(selector = '.duration') ⇒ Object
- #ingredients(selector = '.ingredient') ⇒ Object
-
#initialize(recipe_root, url) ⇒ Recipe
constructor
A new instance of Recipe.
- #instructions(selector = '.instructions') ⇒ Object
- #nutrition(selector = '.nutrition') ⇒ Object
- #photo(selector = '.photo') ⇒ Object
- #published(selector = '.published)') ⇒ Object
- #summary(selector = '.summary') ⇒ Object
- #tags(selector = '.tag') ⇒ Object
- #title(selector = '.fn') ⇒ Object
- #yield(selector = '.yield') ⇒ Object
Constructor Details
#initialize(recipe_root, url) ⇒ Recipe
Returns a new instance of Recipe.
30 31 32 33 |
# File 'lib/lettuce/recipe.rb', line 30 def initialize(recipe_root, url) @root = recipe_root @url = url end |
Class Method Details
.can_parse?(doc, url) ⇒ Boolean
4 5 6 |
# File 'lib/lettuce/recipe.rb', line 4 def can_parse?(doc, url) doc.css('.hrecipe').size > 0 end |
.parse(doc, url) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/lettuce/recipe.rb', line 12 def parse(doc, url) recipe_root = doc.css(@root) if recipe_root.size > 0 self.new(recipe_root[0], url) end end |
.parse_all(doc, url) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/lettuce/recipe.rb', line 19 def parse_all(doc, url) recipes = doc.css(@root) if recipes.size > 0 recipes.collect { |recipe_root| self.new(recipe_root, url) } end end |
Instance Method Details
#author(selector = '.author') ⇒ Object
63 64 65 |
# File 'lib/lettuce/recipe.rb', line 63 def (selector = '.author') @root.css(selector).collect { || .content.strip } end |
#duration(selector = '.duration') ⇒ Object
55 56 57 |
# File 'lib/lettuce/recipe.rb', line 55 def duration(selector = '.duration') @root.css(selector).collect { |duration| duration.content.strip } end |
#ingredients(selector = '.ingredient') ⇒ Object
39 40 41 |
# File 'lib/lettuce/recipe.rb', line 39 def ingredients(selector = '.ingredient') @root.css(selector).collect { |ingredient| ingredient.content.strip } end |
#instructions(selector = '.instructions') ⇒ Object
51 52 53 |
# File 'lib/lettuce/recipe.rb', line 51 def instructions(selector = '.instructions') @root.css(selector)[0].content.strip end |
#nutrition(selector = '.nutrition') ⇒ Object
71 72 73 |
# File 'lib/lettuce/recipe.rb', line 71 def nutrition(selector = '.nutrition') @root.css(selector).collect { |nutrition| nutrition.content.strip } end |
#photo(selector = '.photo') ⇒ Object
43 44 45 |
# File 'lib/lettuce/recipe.rb', line 43 def photo(selector = '.photo') @root.css(selector)[0]['src'] end |
#published(selector = '.published)') ⇒ Object
67 68 69 |
# File 'lib/lettuce/recipe.rb', line 67 def published(selector = '.published)') @root.css(selector)[0].content.strip end |
#summary(selector = '.summary') ⇒ Object
59 60 61 |
# File 'lib/lettuce/recipe.rb', line 59 def summary(selector = '.summary') @root.css(selector)[0].content.strip end |
#tags(selector = '.tag') ⇒ Object
75 76 77 |
# File 'lib/lettuce/recipe.rb', line 75 def (selector = '.tag') @root.css(selector).collect { |tag| tag.content.strip } end |
#title(selector = '.fn') ⇒ Object
35 36 37 |
# File 'lib/lettuce/recipe.rb', line 35 def title(selector = '.fn') @root.css(selector)[0].content.strip end |
#yield(selector = '.yield') ⇒ Object
47 48 49 |
# File 'lib/lettuce/recipe.rb', line 47 def yield(selector = '.yield') @root.css(selector)[0].content.strip end |