Module: IEV

Defined in:
lib/iev/cli.rb,
lib/iev.rb,
lib/iev/db.rb,
lib/iev/cli/ui.rb,
lib/iev/version.rb,
lib/iev/db_cache.rb,
lib/iev/profiler.rb,
lib/iev/converter.rb,
lib/iev/db_writer.rb,
lib/iev/utilities.rb,
lib/iev/relaton_db.rb,
lib/iev/cli/command.rb,
lib/iev/iso_639_code.rb,
lib/iev/term_builder.rb,
lib/iev/source_parser.rb,
lib/iev/data_conversions.rb,
lib/iev/term_attrs_parser.rb,
lib/iev/cli/command_helper.rb,
lib/iev/supersession_parser.rb,
lib/iev/converter/mathml_to_asciimath.rb

Overview

© Copyright 2020 Ribose Inc.

Defined Under Namespace

Modules: CLI, Converter, DataConversions, Utilities Classes: Db, DbCache, DbWriter, Iso639Code, Profiler, RelatonDb, SourceParser, SupersessionParser, TermAttrsParser, TermBuilder

Constant Summary collapse

VERSION =
"0.3.3".freeze

Class Method Summary collapse

Class Method Details

.get(code, lang) ⇒ String?

Scrape Electropedia for term.

if code not found then empty string,

if language not found then nil.

Parameters:

  • code (String)

    for example “103-01-02”

  • lang (String)

    language code, for examle “en”

Returns:

  • (String, nil)

    if found than term,



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/iev.rb', line 37

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