Class: DailyRecipe::Recipe
- Inherits:
-
Object
- Object
- DailyRecipe::Recipe
- Defined in:
- lib/daily_recipe/Recipe.rb
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
-
.scrape_full_recipe(the_recipe) ⇒ Object
Parses JSON to get access to the gigya API info in order to scrape the ratings information.
- .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 @rating 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
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/daily_recipe/Recipe.rb', line 25 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) = parsed[:streamInfo][:avgRatings][:_overall] end |
.scrape_food_network ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/daily_recipe/Recipe.rb', line 10 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| 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
Parses JSON to get access to the gigya API info in order to scrape the ratings information.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/daily_recipe/Recipe.rb', line 36 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 |