Class RBook::WWW::Base
In: lib/rbook/www/base.rb
Parent: Object

Methods

Public Class methods

registers a new scraper with the library. classname - the class to add

[Source]

# File lib/rbook/www/base.rb, line 13
    def self.add_scraper(classname)
      @@scrapers << classname
    end

find a scraper matching the requested id id - a scraper id as a symbol

[Source]

# File lib/rbook/www/base.rb, line 19
    def self.find_scraper(id)
      @@scrapers.each do |scraper|
        return scraper if scraper::SCRAPER_ID == id
      end
      return nil
    end

find any scrapers matching the requested ids ids - an array of scraper id‘s as symbols

[Source]

# File lib/rbook/www/base.rb, line 28
    def self.find_scrapers(ids)
      ret = []
      @@scrapers.each do |scraper|
        ret << scraper if ids.contains?(scraper::SCRAPER_ID)
      end
      return ret
    end

[Source]

# File lib/rbook/www/base.rb, line 81
    def self.scrapers
      @@scrapers
    end

Public Instance methods

This method can be overwritten in each scraper. It should return a hash containing the binary data and mimetype of the largest cover image it can find for the requested isbn

[Source]

# File lib/rbook/www/base.rb, line 38
    def get_cover(isbn)

      info = get_info(isbn)
      return nil if info.nil?
      return nil unless info.kind_of?(Hash)

      link = info[:cover_large] || info[:cover_medium] || info[:cover_thumb]

      return nil if link.nil?

      begin
        response = Net::HTTP.get_response URI.parse(link)
          if response.code != "200"
            raise response.code.to_s
            return nil
          else
            result = {}
            result[:data] = response.body
            result[:content_type] = "image/jpeg"
            return result
          end
      rescue
        return nil
      end
    end

This method can be overwritten in each scraper. It should return a hash of any information on the requested isbn it can find

[Source]

# File lib/rbook/www/base.rb, line 66
    def get_info(isbn)
      nil
    end

This method can be overwritten in each scraper. It should return a link to the requested isbn on the targets website

[Source]

# File lib/rbook/www/base.rb, line 72
    def get_link(isbn)
      nil
    end

return the symbol used to uniquely identify each scraper

[Source]

# File lib/rbook/www/base.rb, line 77
    def scraper_id
      return SCRAPER_ID
    end

[Validate]