Class: RecipeBook::Recipe

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, url = nil) ⇒ Recipe

Returns a new instance of Recipe.



5
6
7
8
# File 'lib/recipe_book/recipe.rb', line 5

def initialize(name = nil, url = nil)
  @name = name
  @url = url
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#ingredientsObject

Returns the value of attribute ingredients.



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

def ingredients
  @ingredients
end

#instructionsObject

Returns the value of attribute instructions.



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

def instructions
  @instructions
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

Class Method Details

.allObject



10
11
12
# File 'lib/recipe_book/recipe.rb', line 10

def self.all
  @@all ||= scrape_recipes
end

.find(id) ⇒ Object



15
16
17
# File 'lib/recipe_book/recipe.rb', line 15

def self.find(id)
  self.all[id-1]
end

.scrape_recipesObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/recipe_book/recipe.rb', line 19

def self.scrape_recipes
  #go to url with list of drinks
  #pulls names of drinks from page
  #pulls url of drink page
  #creates a new instance of Recipe with name and url arguments

  doc = Nokogiri::HTML(open("http://food.ndtv.com/lists/be-your-own-bartender-10-best-cocktail-recipes-751639"))
  names = doc.search("span p strong a").collect {|n| n.text.strip}
  url = doc.search("span p strong a").collect {|url| url.attr("href")}
  arr = names.zip(url)
  arr.collect {|n|new(n[0],n[1])}
end