Class: DailyRecipe::Recipe
- Inherits:
-
Object
- Object
- DailyRecipe::Recipe
- Defined in:
- lib/daily_recipe/Recipe.rb
Constant Summary collapse
- BASE_URL =
"http://www.foodnetwork.com"
Instance Attribute Summary collapse
-
#api_id ⇒ Object
Returns the value of attribute api_id.
-
#cook_time ⇒ Object
Returns the value of attribute cook_time.
-
#name ⇒ Object
Returns the value of attribute name.
-
#rating ⇒ Object
Returns the value of attribute rating.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
- .get_rating(api_id) ⇒ Object
-
.scrape_food_network ⇒ Object
def self.scrape_recipes self.scrape_food_network end.
- .scrape_full_recipe(the_recipe) ⇒ Object
- .today ⇒ Object
Instance Attribute Details
#api_id ⇒ Object
Returns the value of attribute api_id.
4 5 6 |
# File 'lib/daily_recipe/Recipe.rb', line 4 def api_id @api_id end |
#cook_time ⇒ Object
Returns the value of attribute cook_time.
4 5 6 |
# File 'lib/daily_recipe/Recipe.rb', line 4 def cook_time @cook_time end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/daily_recipe/Recipe.rb', line 4 def name @name end |
#rating ⇒ Object
Returns the value of attribute rating.
4 5 6 |
# File 'lib/daily_recipe/Recipe.rb', line 4 def end |
#url ⇒ Object
Returns the value of attribute url.
4 5 6 |
# File 'lib/daily_recipe/Recipe.rb', line 4 def url @url end |
Class Method Details
.get_rating(api_id) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/daily_recipe/Recipe.rb', line 31 def self.(api_id) #@beingy is the man gigya_api_url = "http://comments.us1.gigya.com/comments.getStreamInfo?categoryID=recipe&streamID=API_ID&includeRatingDetails=true&APIKey=3_ClDcX23A7tU8pcydnKyENXSYP5kxCbwH4ZO741ZOujPRY8Ksj2UBnj8Zopb0OX0K&sdk=js_6.3.02&format=jsonp&callback=gigya._.apiAdapters.web.callback" api_id_url = gigya_api_url.gsub("API_ID", api_id) recipe_json = Nokogiri::HTML(open(api_id_url)) part1 = recipe_json.text.gsub("gigya._.apiAdapters.web.callback(","") part2 = part1.gsub("});","}") parsed = JSON.parse(part2, symbolize_names: true) #binding.pry = parsed[:streamInfo][:avgRatings][:_overall] end |
.scrape_food_network ⇒ Object
def self.scrape_recipes
self.scrape_food_network
end
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/daily_recipe/Recipe.rb', line 15 def self.scrape_food_network recipes = [] doc = Nokogiri::HTML(open("http://www.foodnetwork.com/recipes/photos/recipe-of-the-day-what-to-cook-now.html")) doc.search(".feed li").each do |x| #binding.pry recipe = self.new recipe.name = x.search("h6 a").text recipe.cook_time = x.search("dd").text recipe.api_id = (x.css("a.community-rating-stars").attribute("data-rating").value).scan(/\w+\-.+\w+/).join("-") recipe.url = BASE_URL + x.search(".community-rating-stars").attribute("href").value recipe. = (recipe.api_id) recipes << recipe end recipes end |
.scrape_full_recipe(the_recipe) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/daily_recipe/Recipe.rb', line 43 def self.scrape_full_recipe(the_recipe) doc = Nokogiri::HTML(open(the_recipe.url)) ingredients = doc.search("div.ingredients li") puts "" puts "Ingredients" ingredients.each do |ingredient| puts ingredient.text end cooking_instructions = doc.search("div.directions li") cooking_instructions.each do |instruction| puts "" puts instruction.text end end |
.today ⇒ Object
6 7 8 |
# File 'lib/daily_recipe/Recipe.rb', line 6 def self.today self.scrape_food_network end |