Sha256: 4c25783c8caf2e6b238875a5e643ba91dc7415ecf48f6943c3c6e821cb8dce91

Contents?: true

Size: 988 Bytes

Versions: 26

Compression:

Stored size: 988 Bytes

Contents

require 'mechanize'


module Scrapers

  module AllRecipes

    def self.scrape(url)

      results = Hash.new

      Scrapers.agent.get(url).tap do |page|
        results[:url] = page.uri.to_s
        results[:title] = page.title.strip
        results[:ingredients] = scrape_ingredients(page)
        results[:directions] = scrape_directions(page)
        results[:photo] = scrape_photo(page)
      end

      results

    end

    def self.scrape_ingredients(page)
      page.
        search("ul.ingredient-wrap").
        search(".//li").
        map do |i|
        i.text.gsub(/[[:space:]]+/,' ').sub(/^/,'*')
      end
    end

    def self.scrape_directions(page)
      page.
        search("div.directLeft").first.
        search("li").
        map do |i|
        i.text.gsub(/[[:space:]]+/,' ').sub(/^/,'# ')
      end
    end

    def self.scrape_photo(page)
      photo = page.search("img#imgPhoto").first
      Hash[photo.attributes.map{|k,v| [k,v.value]}]
    end

  end

end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
scrapers-3.2.0 lib/scrapers/allrecipes.rb
scrapers-3.1.0 lib/scrapers/allrecipes.rb
scrapers-3.0.0 lib/scrapers/allrecipes.rb
scrapers-2.1.0 lib/scrapers/allrecipes.rb
scrapers-2.0.2 lib/scrapers/allrecipes.rb
scrapers-2.0.1 lib/scrapers/allrecipes.rb
scrapers-2.0.0 lib/scrapers/allrecipes.rb
scrapers-1.5.6 lib/scrapers/allrecipes.rb
scrapers-1.5.5 lib/scrapers/allrecipes.rb
scrapers-1.5.4 lib/scrapers/allrecipes.rb
scrapers-1.5.3 lib/scrapers/allrecipes.rb
scrapers-1.5.2 lib/scrapers/allrecipes.rb
scrapers-1.5.1 lib/scrapers/allrecipes.rb
scrapers-1.5.0 lib/scrapers/allrecipes.rb
scrapers-1.4.0 lib/scrapers/allrecipes.rb
scrapers-1.3.0 lib/scrapers/allrecipes.rb
scrapers-1.2.0 lib/scrapers/allrecipes.rb
scrapers-1.1.0 lib/scrapers/allrecipes.rb
scrapers-1.0.0 lib/scrapers/allrecipes.rb
scrapers-0.4.3 lib/scrapers/allrecipes.rb