Class: RecipeGenerator::Recipe
- Inherits:
-
Object
- Object
- RecipeGenerator::Recipe
- Defined in:
- lib/recipe.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#duration ⇒ Object
Returns the value of attribute duration.
-
#ingredients ⇒ Object
Returns the value of attribute ingredients.
-
#link ⇒ Object
Returns the value of attribute link.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #doc ⇒ Object
-
#initialize(name = nil, duration = nil, description = nil, link = nil) ⇒ Recipe
constructor
A new instance of Recipe.
- #instructions ⇒ Object
Constructor Details
#initialize(name = nil, duration = nil, description = nil, link = nil) ⇒ Recipe
Returns a new instance of Recipe.
19 20 21 22 23 24 25 |
# File 'lib/recipe.rb', line 19 def initialize(name=nil, duration=nil, description=nil, link=nil) @name = name @duration = duration @description = description @link = link @@all << self end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
3 4 5 |
# File 'lib/recipe.rb', line 3 def description @description end |
#duration ⇒ Object
Returns the value of attribute duration.
3 4 5 |
# File 'lib/recipe.rb', line 3 def duration @duration end |
#ingredients ⇒ Object
Returns the value of attribute ingredients.
3 4 5 |
# File 'lib/recipe.rb', line 3 def ingredients @ingredients end |
#link ⇒ Object
Returns the value of attribute link.
3 4 5 |
# File 'lib/recipe.rb', line 3 def link @link end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/recipe.rb', line 3 def name @name end |
Class Method Details
.all ⇒ Object
28 29 30 |
# File 'lib/recipe.rb', line 28 def self.all @@all end |
.find(id) ⇒ Object
32 33 34 |
# File 'lib/recipe.rb', line 32 def self.find(id) self.all[id-1] end |
.new_vegetarian(d) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/recipe.rb', line 10 def self.new_vegetarian(d) self.new( d.css("h3.teaser-item__title a span").text, d.css("ul.teaser-item__info-items li.teaser-item__info-item.teaser-item__info-item--total-time span.mins").text, d.css("div.field-item.even").text, "http://www.bbcgoodfood.com#{d.css("a").attribute("href").text}" ) end |
Instance Method Details
#doc ⇒ Object
49 50 51 |
# File 'lib/recipe.rb', line 49 def doc @doc ||= Nokogiri::HTML(open(self.link)) end |
#instructions ⇒ Object
41 42 43 |
# File 'lib/recipe.rb', line 41 def instructions @instructions ||= doc.xpath("//section[@id='recipe-method']/div/ol/li/p").map.with_index(1) { |directions, i| puts "#{i}. #{directions.text}" } end |