Sha256: 427d990f7fd7da80bbb77267f350dbfed01b5c5c7fcf17d7bc3363ba241f0e6d

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

class TodaysTopDesserts::Scraper

  def self.scrape_desserts
    #returns an array of recipes with a name and url.
    page = Nokogiri::HTML(open("https://www.allrecipes.com/recipes/79/desserts/"))

    page.css("article.list-recipes")[0].css("li")[0..9].collect do |dessert|
        {:name => dessert.css("img").attr("title").text,
          :url => dessert.css("a").attr("href").value
        }
    end

  end

  def self.scrape_recipe(recipe_url)
    #returns a hash of recipe attributes
    page = Nokogiri::HTML(open(recipe_url))

    recipe = {}

    recipe[:author] = page.css(".submitter__name").text.strip
    recipe[:description] = page.css(".submitter__description").text.strip
    recipe[:serving_size] = page.css("#metaRecipeServings").attr("content").value
    recipe[:prep_time] = page.css("time[itemprop='prepTime']").text.strip
    recipe[:cook_time] = page.css("time[itemprop='cookTime']").text.strip
    recipe[:ready_time] = page.css("time[itemprop='totalTime']").text.strip
    recipe[:calorie_count] = page.css(".calorie-count").text.strip

    recipe[:ingredients] = page.css("span[itemprop='ingredients']").collect {|ingredient| ingredient.text.strip}

    recipe[:instructions] = page.css("ol[itemprop='recipeInstructions'] span.recipe-directions__list--item").collect {|instruction| instruction.text.strip}

    recipe

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
todays_top_desserts-0.1.1 lib/todays_top_desserts/scraper.rb