Class: Iev::Scraper
- Inherits:
-
Object
- Object
- Iev::Scraper
- Defined in:
- lib/iev/scraper.rb,
lib/iev/scraper/browser.rb,
lib/iev/scraper/page_parser.rb
Defined Under Namespace
Modules: Browser Classes: PageParser
Constant Summary collapse
- BASE_URL =
"https://www.electropedia.org/iev/iev.nsf/" \ "display?openform&ievref="
Instance Method Summary collapse
-
#fetch_concept(code) ⇒ Object
Fetch and parse concept data for an IEV code.
-
#fetch_page(code) ⇒ Object
Fetch the Electropedia page HTML for a given IEV code.
-
#initialize(browser_opts: {}) ⇒ Scraper
constructor
A new instance of Scraper.
Constructor Details
#initialize(browser_opts: {}) ⇒ Scraper
Returns a new instance of Scraper.
13 14 15 |
# File 'lib/iev/scraper.rb', line 13 def initialize(browser_opts: {}) @browser_opts = browser_opts end |
Instance Method Details
#fetch_concept(code) ⇒ Object
Fetch and parse concept data for an IEV code. Returns a hash with concept data or nil if not found.
29 30 31 32 33 34 |
# File 'lib/iev/scraper.rb', line 29 def fetch_concept(code) doc = fetch_page(code) return nil unless doc PageParser.new(doc, code).parse end |
#fetch_page(code) ⇒ Object
Fetch the Electropedia page HTML for a given IEV code. Returns a Nokogiri document.
19 20 21 22 23 24 25 |
# File 'lib/iev/scraper.rb', line 19 def fetch_page(code) html = Browser.fetch("#{BASE_URL}#{code}", browser_opts: @browser_opts) return nil unless html Nokogiri::HTML(html) end |