Module: Iev
- Defined in:
- lib/iev.rb,
lib/iev/db.rb,
lib/iev/version.rb,
lib/iev/db_cache.rb
Defined Under Namespace
Constant Summary collapse
- VERSION =
"0.3.0".freeze
Class Method Summary collapse
-
.get(code, lang) ⇒ String?
Scrape Electropedia for term.
Class Method Details
.get(code, lang) ⇒ String?
Scrape Electropedia for term.
if code not found then empty string,
if language not found then nil.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/iev.rb', line 17 def self.get(code, lang) url = "http://www.electropedia.org/iev/iev.nsf/"\ "display?openform&ievref=#{code}" doc = Nokogiri::HTML OpenURI.open_uri(url), nil, "UTF-8" xpath = "//table/tr/td/div/font[.=\"#{lang}\"]/../../"\ "following-sibling::td[2]" a = doc&.at(xpath)&.children&.to_xml a&.sub(%r{<br/>.*$}, "") &.sub(%r{, <.*$}, "") &.gsub(%r{<[^>]*>}, "")&.strip end |