Class: Iev::Scraper
- Inherits:
-
Object
- Object
- Iev::Scraper
- Defined in:
- lib/iev/scraper.rb,
lib/iev/scraper/page_parser.rb
Defined Under Namespace
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.
10 11 12 |
# File 'lib/iev/scraper.rb', line 10 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.
25 26 27 28 29 30 |
# File 'lib/iev/scraper.rb', line 25 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.
16 17 18 19 20 21 |
# File 'lib/iev/scraper.rb', line 16 def fetch_page(code) html = ScraperBrowser.fetch("#{BASE_URL}#{code}", browser_opts: @browser_opts) return nil unless html Nokogiri::HTML(html) end |