class IsoDoc::Iso::Metadata

Public Class Methods

new(lang, script, i18n) click to toggle source
Calls superclass method
# File lib/isodoc/iso/metadata.rb, line 6
def initialize(lang, script, i18n)
  super
  set(:tc, "XXXX")
  set(:sc, "XXXX")
  set(:wg, "XXXX")
  set(:editorialgroup, [])
  set(:secretariat, "XXX")
  set(:obsoletes, nil)
  set(:obsoletes_part, nil)
end

Public Instance Methods

amd_label(lang) click to toggle source
# File lib/isodoc/iso/metadata.rb, line 74
def amd_label(lang)
  case lang
  when "en" then "AMENDMENT"
  when "fr" then "AMENDMENT"
  end
end
amd_prefix(num, lang) click to toggle source
# File lib/isodoc/iso/metadata.rb, line 102
def amd_prefix(num, lang)
  "#{amd_label(lang)} #{num}"
end
author(xml, _out) click to toggle source
Calls superclass method
# File lib/isodoc/iso/metadata.rb, line 177
def author(xml, _out)
  super
  tc(xml)
  sc(xml)
  wg(xml)
  secretariat(xml)
end
compose_title(main, intro, part, partnum, subpartnum, lang) click to toggle source
# File lib/isodoc/iso/metadata.rb, line 110
def compose_title(main, intro, part, partnum, subpartnum, lang)
  main = main.nil? ? "" : @c.encode(main.text, :hexadecimal)
  intro &&
    main = "#{@c.encode(intro.text, :hexadecimal)} — #{main}"
  if part
    suffix = part_title(part, partnum, subpartnum, lang)
    main = "#{main} — #{suffix}"
  end
  main
end
corr_label(lang) click to toggle source
# File lib/isodoc/iso/metadata.rb, line 81
def corr_label(lang)
  case lang
  when "en" then "TECHNICAL CORRIGENDUM"
  when "fr" then "RECTIFICATIF TECHNIQUE"
  end
end
corr_prefix(num, lang) click to toggle source
# File lib/isodoc/iso/metadata.rb, line 106
def corr_prefix(num, lang)
  "#{corr_label(lang)} #{num}"
end
docid(isoxml, _out) click to toggle source
# File lib/isodoc/iso/metadata.rb, line 54
def docid(isoxml, _out)
  dn = isoxml.at(ns("//bibdata/docidentifier[@type = 'ISO']"))
  set(:docnumber, dn&.text)
  tcdn = isoxml.xpath(ns("//bibdata/docidentifier[@type = 'iso-tc']"))
  set(:tc_docnumber, tcdn.map(&:text))
  dn = isoxml.at(ns("//bibdata/docidentifier[@type = 'iso-with-lang']"))
  set(:docnumber_lang, dn&.text)
  dn = isoxml.at(ns("//bibdata/docidentifier[@type = 'iso-reference']"))
  set(:docnumber_reference, dn&.text)
end
docstatus(isoxml, _out) click to toggle source
# File lib/isodoc/iso/metadata.rb, line 31
def docstatus(isoxml, _out)
  docstatus = isoxml.at(ns("//bibdata/status/stage"))
  set(:unpublished, false)
  if docstatus
    set(:stage, docstatus.text)
    set(:stage_int, docstatus.text.to_i)
    set(:unpublished, unpublished(docstatus.text))
    set(:statusabbr, status_abbrev(docstatus["abbreviation"] || "??",
                                   isoxml&.at(ns("//bibdata/status/substage"))&.text,
                                   isoxml&.at(ns("//bibdata/status/iteration"))&.text,
                                   isoxml&.at(ns("//bibdata/version/draft"))&.text,
                                   isoxml&.at(ns("//bibdata/ext/doctype"))&.text))
    unpublished(docstatus.text) and
      set(:stageabbr, docstatus["abbreviation"])
  end
  revdate = isoxml.at(ns("//bibdata/version/revision-date"))
  set(:revdate, revdate&.text)
end
doctype(isoxml, _out) click to toggle source
Calls superclass method
# File lib/isodoc/iso/metadata.rb, line 221
def doctype(isoxml, _out)
  super
  ics = []
  isoxml.xpath(ns("//bibdata/ext/ics/code")).each { |i| ics << i.text }
  set(:ics, ics.empty? ? nil : ics.join(", "))
  a = isoxml.at(ns("//bibdata/ext/horizontal")) and set(:horizontal,
                                                        a.text)
end
part_label(lang) click to toggle source

we don't leave this to i18n.rb, because we have both English and French titles in the same document

# File lib/isodoc/iso/metadata.rb, line 67
def part_label(lang)
  case lang
  when "en" then "Part"
  when "fr" then "Partie"
  end
end
part_prefix(partnum, subpartnum, lang) click to toggle source
# File lib/isodoc/iso/metadata.rb, line 97
def part_prefix(partnum, subpartnum, lang)
  partnum = "#{partnum}&ndash;#{subpartnum}" if partnum && subpartnum
  "#{part_label(lang)}&nbsp;#{partnum}"
end
part_title(part, partnum, subpartnum, lang) click to toggle source
# File lib/isodoc/iso/metadata.rb, line 88
def part_title(part, partnum, subpartnum, lang)
  return "" unless part

  suffix = @c.encode(part.text, :hexadecimal)
  partnum = "#{partnum}&ndash;#{subpartnum}" if partnum && subpartnum
  suffix = "#{part_label(lang)}&nbsp;#{partnum}: " + suffix if partnum
  suffix
end
sc(xml) click to toggle source
# File lib/isodoc/iso/metadata.rb, line 196
def sc(xml)
  sc_num = xml.at(ns("//bibdata/ext/editorialgroup/subcommittee/@number"))
  sc_type = xml.at(ns("//bibdata/ext/editorialgroup/subcommittee/@type"))&.text || "SC"
  if sc_num
    scid = "#{sc_type} #{sc_num.text}"
    set(:sc, scid)
    set(:editorialgroup, get[:editorialgroup] << scid)
  end
end
secretariat(xml) click to toggle source
# File lib/isodoc/iso/metadata.rb, line 216
def secretariat(xml)
  sec = xml.at(ns("//bibdata/ext/editorialgroup/secretariat"))
  set(:secretariat, sec.text) if sec
end
status_abbrev(stage, _substage, iter, draft, doctype) click to toggle source
# File lib/isodoc/iso/metadata.rb, line 17
def status_abbrev(stage, _substage, iter, draft, doctype)
  return "" unless stage

  if %w(technical-report technical-specification).include?(doctype)
    stage = "DTS" if stage == "DIS"
    stage = "FDTS" if stage == "FDIS"
  end
  if %w(PWI NWIP WD CD).include?(stage) && iter
    stage += iter
  end
  stage = "Pre#{stage}" if /^0\./.match?(draft)
  stage
end
subtitle(isoxml, _out) click to toggle source
# File lib/isodoc/iso/metadata.rb, line 158
def subtitle(isoxml, _out)
  lang = @lang == "fr" ? "en" : "fr"
  intro, main, part, amd = title_parts(isoxml, lang)
  partnumber, subpartnumber, amdnumber, corrnumber = title_nums(isoxml)

  set(:docsubtitlemain, @c.encode(main ? main.text : "", :hexadecimal))
  main = compose_title(main, intro, part, partnumber, subpartnumber, lang)
  set(:docsubtitle, main)
  if intro
    set(:docsubtitleintro,
        @c.encode(intro ? intro.text : "", :hexadecimal))
  end
  set(:docsubtitlepartlabel, part_prefix(partnumber, subpartnumber, lang))
  set(:docsubtitlepart, @c.encode(part.text, :hexadecimal)) if part
  set(:docsubtitleamdlabel, amd_prefix(amdnumber, lang)) if amdnumber
  set(:docsubtitleamd, @c.encode(amd.text, :hexadecimal)) if amd
  set(:docsubtitlecorrlabel, corr_prefix(corrnumber, lang)) if corrnumber
end
tc(xml) click to toggle source
# File lib/isodoc/iso/metadata.rb, line 185
def tc(xml)
  tc_num = xml.at(ns("//bibdata/ext/editorialgroup/technical-committee/@number"))
  tc_type = xml.at(ns("//bibdata/ext/editorialgroup/technical-committee/@type"))
    &.text || "TC"
  if tc_num
    tcid = "#{tc_type} #{tc_num.text}"
    set(:tc,  tcid)
    set(:editorialgroup, get[:editorialgroup] << tcid)
  end
end
title(isoxml, _out) click to toggle source
# File lib/isodoc/iso/metadata.rb, line 139
def title(isoxml, _out)
  lang = @lang == "fr" ? "fr" : "en"
  intro, main, part, amd = title_parts(isoxml, lang)
  partnumber, subpartnumber, amdnumber, corrnumber = title_nums(isoxml)

  set(:doctitlemain, @c.encode(main ? main.text : "", :hexadecimal))
  main = compose_title(main, intro, part, partnumber, subpartnumber, lang)
  set(:doctitle, main)
  if intro
    set(:doctitleintro,
        @c.encode(intro ? intro.text : "", :hexadecimal))
  end
  set(:doctitlepartlabel, part_prefix(partnumber, subpartnumber, lang))
  set(:doctitlepart, @c.encode(part.text, :hexadecimal)) if part
  set(:doctitleamdlabel, amd_prefix(amdnumber, lang)) if amdnumber
  set(:doctitleamd, @c.encode(amd.text, :hexadecimal)) if amd
  set(:doctitlecorrlabel, corr_prefix(corrnumber, lang)) if corrnumber
end
title_nums(isoxml) click to toggle source
# File lib/isodoc/iso/metadata.rb, line 121
def title_nums(isoxml)
  [isoxml.at(ns("//bibdata//project-number/@part")),
   isoxml.at(ns("//bibdata//project-number/@subpart")),
   isoxml.at(ns("//bibdata//project-number/@amendment")),
   isoxml.at(ns("//bibdata//project-number/@corrigendum"))]
end
title_parts(isoxml, lang) click to toggle source
# File lib/isodoc/iso/metadata.rb, line 128
def title_parts(isoxml, lang)
  [isoxml.at(ns("//bibdata//title[@type='title-intro' and "\
                "@language='#{lang}']")),
   isoxml.at(ns("//bibdata//title[@type='title-main' and "\
                "@language='#{lang}']")),
   isoxml.at(ns("//bibdata//title[@type='title-part' and "\
                "@language='#{lang}']")),
   isoxml.at(ns("//bibdata//title[@type='title-amd' and "\
                "@language='#{lang}']"))]
end
unpublished(status) click to toggle source
# File lib/isodoc/iso/metadata.rb, line 50
def unpublished(status)
  status.to_i.positive? && status.to_i < 60
end
wg(xml) click to toggle source
# File lib/isodoc/iso/metadata.rb, line 206
def wg(xml)
  wg_num = xml.at(ns("//bibdata/ext/editorialgroup/workgroup/@number"))
  wg_type = xml.at(ns("//bibdata/ext/editorialgroup/workgroup/@type"))&.text || "WG"
  if wg_num
    wgid = "#{wg_type} #{wg_num.text}"
    set(:wg, wgid)
    set(:editorialgroup, get[:editorialgroup] << wgid)
  end
end