Module: RelatonIev

Defined in:
lib/relaton_iev.rb,
lib/relaton_iev/version.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.iev_cleanup(xmldoc, bibdb = nil) ⇒ Nokogiri::XML::Element

Parameters:

  • xmldoc (Nokogiri::XML::Document)
  • bibdb (Relaton::Db, NilClass) (defaults to: nil)

Returns:

  • (Nokogiri::XML::Element)


52
53
54
55
56
# File 'lib/relaton_iev.rb', line 52

def iev_cleanup(xmldoc, bibdb = nil)
  iev = xmldoc.at("//bibitem[docidentifier = 'IEC 60050:2011']") || return
  parts = linksIev2iec60050part(xmldoc)
  refsIev2iec60050part(xmldoc, parts, iev, bibdb)
end

.linksIev2iec60050part(xmldoc) ⇒ Set<String>

converts generic IEV citation to citation of IEC 60050-n assumes IEV citations are of form <eref type=“inline” bibitemid=“a” citeas=“IEC 60050”> <locality type=“clause”><referenceFrom>101-01-01</referenceFrom></locality></eref>

Parameters:

  • xmldoc (Nokogiri::XML::Documet)

Returns:

  • (Set<String>)


15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/relaton_iev.rb', line 15

def linksIev2iec60050part(xmldoc)
  parts = Set.new
  xmldoc.xpath("//eref[@citeas = 'IEC 60050:2011'] | "\
               "//origin[@citeas = 'IEC 60050:2011']").each do |x|
    cl = x&.at("./locality[@type = 'clause']/referenceFrom")&.text || next
    m = /^(\d+)/.match cl || next
    parts << m[0]
    x["citeas"] = x["citeas"].sub(/60050/, "60050-#{m[0]}")
    x["bibitemid"] = "IEC60050-#{m[0]}"
  end
  parts
end

.refsIev2iec60050part(xmldoc, parts, iev, bibdb = nil) ⇒ Nokogiri::XML::Element

replace generic IEV reference with references to all extracted IEV parts

Parameters:

  • xmodoc (Nokogiri::XML::Document)
  • parts (Set<String>)
  • iev (Nokogiri::XML::Element)
  • bibdb (Relaton::Db, NilClass) (defaults to: nil)

Returns:

  • (Nokogiri::XML::Element)


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

def refsIev2iec60050part(xmldoc, parts, iev, bibdb = nil)
  new_iev = ""
  parts.sort.each do |p|
    hit = bibdb&.fetch("IEC 60050-#{p}", nil, keep_year: true) || next
    new_iev += hit.to_xml.sub(/ id="[^"]+"/, %{ id="IEC60050-#{p}"})
    date = hit.date[0].on.year
    xmldoc.xpath("//*[@citeas = 'IEC 60050-#{p}:2011']").each do |x|
      x["citeas"] = x["citeas"].sub(/:2011$/, ":#{date}")
    end
  end
  iev.replace(new_iev)
end