Class: Grubby::JsonScraper
- Defined in:
- lib/grubby/json_scraper.rb
Instance Attribute Summary collapse
-
#json ⇒ Hash, Array
readonly
The parsed JSON data being scraped.
Attributes inherited from Scraper
Class Method Summary collapse
-
.scrape_file(path, agent = $grubby) ⇒ Grubby::JsonScraper
Scrapes a locally-stored file.
Instance Method Summary collapse
-
#initialize(source) ⇒ JsonScraper
constructor
A new instance of JsonScraper.
Methods inherited from Scraper
#[], each, fields, scrape, scrapes, #to_h
Constructor Details
#initialize(source) ⇒ JsonScraper
Returns a new instance of JsonScraper.
11 12 13 14 |
# File 'lib/grubby/json_scraper.rb', line 11 def initialize(source) @json = source.assert!(Grubby::JsonParser).json super end |
Instance Attribute Details
#json ⇒ Hash, Array (readonly)
The parsed JSON data being scraped.
6 7 8 |
# File 'lib/grubby/json_scraper.rb', line 6 def json @json end |
Class Method Details
.scrape_file(path, agent = $grubby) ⇒ Grubby::JsonScraper
Scrapes a locally-stored file. This method is intended for use with subclasses of Grubby::JsonScraper
.
31 32 33 |
# 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 |