Class: RecipeBook::Recipe
- Inherits:
-
Object
- Object
- RecipeBook::Recipe
- Defined in:
- lib/recipe_book/recipe.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#ingredients ⇒ Object
Returns the value of attribute ingredients.
-
#instructions ⇒ Object
Returns the value of attribute instructions.
-
#name ⇒ Object
Returns the value of attribute name.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name = nil, url = nil) ⇒ Recipe
constructor
A new instance of Recipe.
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
#description ⇒ Object
Returns the value of attribute description.
3 4 5 |
# File 'lib/recipe_book/recipe.rb', line 3 def description @description end |
#ingredients ⇒ Object
Returns the value of attribute ingredients.
3 4 5 |
# File 'lib/recipe_book/recipe.rb', line 3 def ingredients @ingredients end |
#instructions ⇒ Object
Returns the value of attribute instructions.
3 4 5 |
# File 'lib/recipe_book/recipe.rb', line 3 def instructions @instructions end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/recipe_book/recipe.rb', line 3 def name @name end |
#url ⇒ Object
Returns the value of attribute url.
3 4 5 |
# File 'lib/recipe_book/recipe.rb', line 3 def url @url end |
Class Method Details
.all ⇒ Object
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_recipes ⇒ Object
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 |