Class: RecipeGenerator::Recipe

Inherits:
Object
  • Object
show all
Defined in:
lib/recipe.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#descriptionObject

Returns the value of attribute description.



3
4
5
# File 'lib/recipe.rb', line 3

def description
  @description
end

#durationObject

Returns the value of attribute duration.



3
4
5
# File 'lib/recipe.rb', line 3

def duration
  @duration
end

#ingredientsObject

Returns the value of attribute ingredients.



3
4
5
# File 'lib/recipe.rb', line 3

def ingredients
  @ingredients
end

Returns the value of attribute link.



3
4
5
# File 'lib/recipe.rb', line 3

def link
  @link
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/recipe.rb', line 3

def name
  @name
end

Class Method Details

.allObject



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

#docObject



49
50
51
# File 'lib/recipe.rb', line 49

def doc
 @doc ||= Nokogiri::HTML(open(self.link))
end

#instructionsObject



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