class Catpedia::Scraper

Constants

URL

Public Class Methods

scrape_cat_details(url) click to toggle source
# File lib/catpedia/scraper.rb, line 15
def self.scrape_cat_details(url) #return hash of details for a single cat
    cat = {}
    page = Nokogiri::HTML(open(url))
    cat[:name] = page.css(".breed-detail h1").text.strip.gsub("\t","").gsub("\r","").gsub("\n","")
    cat[:summary] = page.css("#breed-detail p").text.strip.gsub("\t","").gsub("\r","").gsub("\n","")
    cat[:history] = page.css("#history .richtext  p").text.strip.gsub("\t","").gsub("\r","").gsub("\n","")
    cat[:personality] = page.css("#personality .richtext  p").text.strip.gsub("\t","").gsub("\r","").gsub("\n","")
    cat[:health] = page.css("#health .richtext  p").text.strip.gsub("\t","").gsub("\r","").gsub("\n","")
    cat[:grooming] = page.css("#grooming .richtext  p").text.strip.gsub("\t","").gsub("\r","").gsub("\n","")
    cat
end
scrape_cats() click to toggle source
# File lib/catpedia/scraper.rb, line 5
def self.scrape_cats #return array of all cat objects, each with detailed attributes
    cat_urls = Nokogiri::HTML(open(URL)).css("#hub-breed-list-container ul li a")
    cat_urls.each do |e|
        url = "http://www.vetstreet.com/" + e.attr('href') 
        cat_details_hash = scrape_cat_details(url)
        Catpedia::Cat.new(cat_details_hash)
    end
    Catpedia::Cat.all
end