class Grubby::JsonScraper

Attributes

json[R]

The parsed JSON data being scraped.

@return [Hash, Array]

Public Class Methods

new(source) click to toggle source

@param source [Grubby::JsonParser] @raise [Grubby::Scraper::Error]

if any {Scraper.scrapes} blocks fail
Calls superclass method Grubby::Scraper::new
# File lib/grubby/json_scraper.rb, line 11
def initialize(source)
  @json = source.assert!(Grubby::JsonParser).json
  super
end
scrape_file(path, agent = $grubby) click to toggle source

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

@example

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

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

@param path [String] @param agent [Mechanize] @return [Grubby::JsonScraper] @raise [Grubby::Scraper::Error]

if any {Scraper.scrapes} blocks fail
# File lib/grubby/json_scraper.rb, line 31
def self.scrape_file(path, agent = $grubby)
  self.new(Grubby::JsonParser.read_local(path).tap{|parser| parser.mech = agent })
end