Class: Grubby::PageScraper

Inherits:
Scraper
  • Object
show all
Defined in:
lib/grubby/page_scraper.rb

Instance Attribute Summary collapse

Attributes inherited from Scraper

#errors, #source

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Scraper

#[], each, fields, scrape, scrapes, #to_h

Constructor Details

#initialize(source) ⇒ PageScraper

Returns a new instance of PageScraper.

Parameters:

Raises:



11
12
13
14
# File 'lib/grubby/page_scraper.rb', line 11

def initialize(source)
  @page = source.assert!(Mechanize::Page)
  super
end

Instance Attribute Details

#pageMechanize::Page (readonly)

The Page being scraped.

Returns:



6
7
8
# File 'lib/grubby/page_scraper.rb', line 6

def page
  @page
end

Class Method Details

.scrape_file(path, agent = $grubby) ⇒ Grubby::PageScraper

Scrapes a locally-stored file. This method is intended for use with subclasses of Grubby::PageScraper.

Examples:

class MyScraper < Grubby::PageScraper
  # ...
end

MyScraper.scrape_file("path/to/local_file.html")  # === MyScraper

Parameters:

  • path (String)
  • agent (Mechanize) (defaults to: $grubby)

Returns:

Raises:



31
32
33
# File 'lib/grubby/page_scraper.rb', line 31

def self.scrape_file(path, agent = $grubby)
  self.new(Mechanize::Page.read_local(path).tap{|page| page.mech = agent })
end