Sha256: 49bad14d8b2adf764760f95c8a45ddbbaf924c335ef45db689167a90887521be

Contents?: true

Size: 802 Bytes

Versions: 2

Compression:

Stored size: 802 Bytes

Contents

require "iev/version"
require "iev/db"
require "open-uri"
require "nokogiri"

module Iev
  #
  # Scrape Electropedia for term.
  #
  # @param [String] code for example "103-01-02"
  # @param [String] lang language code, for examle "en"
  #
  # @return [String, nil] if found than term,
  # if code not found then empty string,
  #   if language not found then nil.
  #
  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{, &lt;.*$}, "")
      &.gsub(%r{<[^>]*>}, "")&.strip
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
iev-0.3.1 lib/iev.rb
iev-0.3.0 lib/iev.rb