class Scrapie

Public Class Methods

after_fetch() click to toggle source
# File lib/scrapie.rb, line 51
def self.after_fetch
  
end
attributes(attributes) click to toggle source
# File lib/scrapie.rb, line 16
def self.attributes(attributes)
  @attributes = attributes
  attributes.each {|name,page_selector|
    self.send(:attr_accessor, name)
  }
end
before_fetch() click to toggle source

Callbacks # TODO

# File lib/scrapie.rb, line 47
def self.before_fetch
  
end
find(opts = {}) click to toggle source

find() find(:foo => bar) find(:foo => bar, :baz => bizzle)

# File lib/scrapie.rb, line 26
def self.find(opts = {})
  raise NoAttributesException unless (@attributes and @attributes.size > 0)
  a = Mechanize.new
  
  # Let's build out the parameters now
  params = Hash[opts.collect{|k,v|
    [@params[k], v] if @params and @params[k]
  }]
  
  page = a.send(@http_method || :get, @url, params)
  
  new_object = self.new
  @attributes.each {|name, page_selector|
    new_object.send(name + '=', page.search(page_selector).inner_html)
  }
  
  new_object
end
http_method(method) click to toggle source
# File lib/scrapie.rb, line 13
def self.http_method(method)
  @http_method = method
end
params(params) click to toggle source
# File lib/scrapie.rb, line 10
def self.params(params)
  @params = params
end
url(url) click to toggle source
# File lib/scrapie.rb, line 7
def self.url(url)
  @url = url
end