class RecipeGenerator::Recipe
Attributes
description[RW]
duration[RW]
ingredients[RW]
link[RW]
name[RW]
Public Class Methods
all()
click to toggle source
# File lib/recipe.rb, line 28 def self.all @@all end
find(id)
click to toggle source
# File lib/recipe.rb, line 32 def self.find(id) self.all[id-1] end
new(name=nil, duration=nil, description=nil, link=nil)
click to toggle source
# 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
new_vegetarian(d)
click to toggle source
# 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
Public Instance Methods
doc()
click to toggle source
# File lib/recipe.rb, line 49 def doc @doc ||= Nokogiri::HTML(open(self.link)) end
instructions()
click to toggle source
# 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