Class: Grubby::PageScraper
- Defined in:
- lib/grubby/page_scraper.rb
Instance Attribute Summary collapse
-
#page ⇒ Mechanize::Page
readonly
The Page being scraped.
Attributes inherited from Scraper
Class Method Summary collapse
-
.scrape_file(path, agent = $grubby) ⇒ Grubby::PageScraper
Scrapes a locally-stored file.
Instance Method Summary collapse
-
#initialize(source) ⇒ PageScraper
constructor
A new instance of PageScraper.
Methods inherited from Scraper
#[], each, fields, scrape, scrapes, #to_h
Constructor Details
#initialize(source) ⇒ PageScraper
Returns a new instance of PageScraper.
11 12 13 14 15 16 17 |
# File 'lib/grubby/page_scraper.rb', line 11 def initialize(source) unless source.is_a?(Mechanize::Page) raise ArgumentError, "source must be a Mechanize::Page object" end @page = source super end |
Instance Attribute Details
#page ⇒ Mechanize::Page (readonly)
The Page being scraped.
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.
34 35 36 |
# File 'lib/grubby/page_scraper.rb', line 34 def self.scrape_file(path, agent = $grubby) self.new(Mechanize::Page.read_local(path).tap{|page| page.mech = agent }) end |