module IsoDoc::ITU::BaseConvert

Constants

FRONT_CLAUSE
IGNORE_IDS

Public Instance Methods

annex(isoxml, out) click to toggle source
# File lib/isodoc/itu/base_convert.rb, line 72
def annex(isoxml, out)
  isoxml.xpath(ns("//annex")).each do |c|
    @meta.get[:doctype_original] == "recommendation-annex" or
      page_break(out)
    out.div **attr_code(id: c["id"], class: "Section3") do |s|
      annex_name(c, nil, s) unless c.at(ns("./title"))
      c.elements.each do |c1|
        if c1.name == "title" then annex_name(c, c1, s)
        else
          parse(c1, s)
        end
      end
    end
  end
end
annex_name(annex, name, div) click to toggle source
# File lib/isodoc/itu/base_convert.rb, line 55
def annex_name(annex, name, div)
  r_a = @meta.get[:doctype_original] == "recommendation-annex"
  div.h1 **{ class: r_a ? "RecommendationAnnex" : "Annex" } do |t|
    name&.children&.each { |c2| parse(c2, t) }
  end
  @meta.get[:doctype_original] == "resolution" or
    annex_obligation_subtitle(annex, div)
end
annex_obligation_subtitle(annex, div) click to toggle source
# File lib/isodoc/itu/base_convert.rb, line 64
def annex_obligation_subtitle(annex, div)
  info = annex["obligation"] == "informative"
  div.p **{ class: "annex_obligation" } do |p|
    p << (info ? @i18n.inform_annex : @i18n.norm_annex)
      .sub(/%/, @meta.get[:doctype] || "")
  end
end
biblio_list(f, div, biblio) click to toggle source
# File lib/isodoc/itu/ref.rb, line 24
def biblio_list(f, div, biblio)
  div.table **{ class: "biblio", border: "0" } do |t|
    i = 0
    t.tbody do |tbody|
      f.elements.each do |b|
        if b.name == "bibitem"
          next if implicit_reference(b)

          i += 1
          nonstd_bibitem(tbody, b, i, biblio)
        else
          unless %w(title clause references).include? b.name
            tbody.tx { |tx| parse(b, tx) }
          end
        end
      end
    end
  end
  f.xpath(ns("./clause | ./references")).each do |x|
    parse(x, div)
  end
end
bracket_if_num(x) click to toggle source
# File lib/isodoc/itu/ref.rb, line 47
def bracket_if_num(x)
  return nil if x.nil?

  x = x.text.sub(/^\[/, "").sub(/\]$/, "")
  "[#{x}]"
end
bracket_opt(b) click to toggle source
# File lib/isodoc/itu/terms.rb, line 30
def bracket_opt(b)
  return b if b.nil?
  return b if /^\[.+\]$/.match(b)
  "[#{b}]"
end
clause(isoxml, out) click to toggle source

can have supertitle in resolution

# File lib/isodoc/itu/base_convert.rb, line 172
def clause(isoxml, out)
  isoxml.xpath(ns(middle_clause(isoxml))).each do |c|
    clause_core(c, out)
  end
end
clause_core(clause, out) click to toggle source
# File lib/isodoc/itu/base_convert.rb, line 178
def clause_core(clause, out)
  out.div **attr_code(clause_attrs(clause)) do |s|
    clause.elements.each do |c1|
      if c1.name == "title" then clause_name(nil, c1, s, nil)
      else
        parse(c1, s)
      end
    end
  end
end
clausedelim() click to toggle source
# File lib/isodoc/itu/base_convert.rb, line 28
def clausedelim
  ""
end
cleanup(docxml) click to toggle source
Calls superclass method
# File lib/isodoc/itu/cleanup.rb, line 4
def cleanup(docxml)
  super
  term_cleanup(docxml)
  refs_cleanup(docxml)
  title_cleanup(docxml)
end
doctype_title(id) click to toggle source
# File lib/isodoc/itu/ref.rb, line 90
def doctype_title(id)
  type = id.parent&.at(ns("./ext/doctype"))&.text || "recommendation"
  if type == "recommendation" &&
      /^(?<prefix>ITU-[A-Z] [A-Z])[ .-]Sup[a-z]*\. ?(?<num>\d+)$/ =~ id.text
    "#{prefix}-series Recommendations – Supplement #{num}"
  else
    d = docid_prefix(id["type"], id.text.sub(/^\[/, "").sub(/\]$/, ""))
    "#{titlecase(type)} #{d}"
  end
end
info(isoxml, out) click to toggle source
Calls superclass method
# File lib/isodoc/itu/base_convert.rb, line 88
def info(isoxml, out)
  @meta.ip_notice_received isoxml, out
  @meta.techreport isoxml, out
  super
end
middle_title(isoxml, out) click to toggle source
# File lib/isodoc/itu/base_convert.rb, line 94
def middle_title(isoxml, out)
  if @meta.get[:doctype] == "Resolution"
    middle_title_resolution(isoxml, out)
  else
    middle_title_recommendation(isoxml, out)
  end
end
middle_title_recommendation(isoxml, out) click to toggle source
# File lib/isodoc/itu/base_convert.rb, line 125
def middle_title_recommendation(isoxml, out)
  out.p(**{ class: "zzSTDTitle1" }) do |p|
    id = @meta.get[:docnumber] and p << "#{@meta.get[:doctype]} #{id}"
  end
  out.p(**{ class: "zzSTDTitle2" }) do |p|
    p << @meta.get[:doctitle]
    isoxml.xpath(ns("//note[@type = 'title-footnote']")).each do |f|
      footnote_parse(f, p)
    end
  end
  s = @meta.get[:docsubtitle] and
    out.p(**{ class: "zzSTDTitle3" }) { |p| p << s }
end
middle_title_resolution(isoxml, out) click to toggle source
# File lib/isodoc/itu/base_convert.rb, line 102
def middle_title_resolution(isoxml, out)
  res = isoxml.at(ns("//bibdata/title[@type = 'resolution']"))
  out.p(**{ align: "center", style: "text-align:center;" }) do |p|
    res.children.each { |n| parse(n, p) }
  end
  out.p(**{ class: "zzSTDTitle2" }) { |p| p << @meta.get[:doctitle] }
  middle_title_resolution_subtitle(isoxml, out)
end
middle_title_resolution_subtitle(isoxml, out) click to toggle source
# File lib/isodoc/itu/base_convert.rb, line 111
def middle_title_resolution_subtitle(isoxml, out)
  out.p(**{ align: "center", style: "text-align:center;" }) do |p|
    p.i do |i|
      i << "("
      isoxml.at(ns("//bibdata/title[@type = 'resolution-placedate']"))
        .children.each { |n| parse(n, i) }
      i << ")"
    end
    isoxml.xpath(ns("//note[@type = 'title-footnote']")).each do |f|
      footnote_parse(f, p)
    end
  end
end
multi_bibitem_ref_code(b) click to toggle source
# File lib/isodoc/itu/ref.rb, line 70
def multi_bibitem_ref_code(b)
  id = b.xpath(ns("./docidentifier[not(@type = 'metanorma' or "\
                  "#{IGNORE_IDS})]"))
  id.empty? and
    id = b.xpath(ns("./docidentifier[not(@type = 'metanorma')]"))
  return [] if id.empty?

  id.sort_by { |i| i["type"] == "ITU" ? 0 : 1 }
end
nonstd_bibitem(list, b, _ordinal, biblio) click to toggle source
# File lib/isodoc/itu/ref.rb, line 8
def nonstd_bibitem(list, b, _ordinal, biblio)
  list.tr **attr_code(iso_bibitem_entry_attrs(b, biblio)) do |ref|
    id = render_identifier(bibitem_ref_code(b))
    ref.td **{ style: "vertical-align:top" } do |td|
      td << (id[0] || "[#{id[1]}]")
        &.gsub(/-/, "&#x2011;")&.gsub(/ /, "&#xa0;")
      date_note_process(b, td)
    end
    ref.td { |td| reference_format(b, td) }
  end
end
note_delim() click to toggle source
# File lib/isodoc/itu/base_convert.rb, line 32
def note_delim
  " &ndash; "
end
note_p_parse(node, div) click to toggle source
# File lib/isodoc/itu/base_convert.rb, line 139
def note_p_parse(node, div)
  name = node&.at(ns("./name"))&.remove
  div.p do |p|
    name and p.span **{ class: "note_label" } do |s|
      name.children.each { |n| parse(n, s) }
      s << note_delim
    end
    node.first_element_child.children.each { |n| parse(n, p) }
  end
  node.element_children[1..-1].each { |n| parse(n, div) }
end
note_parse(node, out) click to toggle source
Calls superclass method
# File lib/isodoc/itu/base_convert.rb, line 165
def note_parse(node, out)
  return if node["type"] == "title-footnote"

  super
end
note_parse1(node, div) click to toggle source
# File lib/isodoc/itu/base_convert.rb, line 151
def note_parse1(node, div)
  name = node&.at(ns("./name"))&.remove
  div.p do |p|
    name and p.span **{ class: "note_label" } do |s|
      name.children.each { |n| parse(n, s) }
    end
  end
  node.children.each { |n| parse(n, div) }
end
ol_depth(node) click to toggle source
Calls superclass method
# File lib/isodoc/itu/base_convert.rb, line 42
def ol_depth(node)
  return super unless node["class"] == "steps" ||
    node.at(".//ancestor::xmlns:ol[@class = 'steps']")

  depth = node.ancestors("ul, ol").size + 1
  type = :arabic
  type = :alphabet if [2, 7].include? depth
  type = :roman if [3, 8].include? depth
  type = :alphabet_upper if [4, 9].include? depth
  type = :roman_upper if [5, 10].include? depth
  ol_style(type)
end
para_class(node) click to toggle source
Calls superclass method
# File lib/isodoc/itu/base_convert.rb, line 36
def para_class(node)
  return "supertitle" if node["class"] == "supertitle"

  super
end
pref_ref_code(b) click to toggle source
Calls superclass method
# File lib/isodoc/itu/ref.rb, line 63
def pref_ref_code(b)
  b.at(ns("./docidentifier[@type = 'ITU']")) || super
end
preface(isoxml, out) click to toggle source
# File lib/isodoc/itu/base_convert.rb, line 14
def preface(isoxml, out)
  isoxml.xpath(ns(FRONT_CLAUSE)).each do |c|
    next unless is_clause?(c.name)

    title = c&.at(ns("./title"))
    out.div **attr_code(clause_attrs(c)) do |s|
      clause_name(nil, title, s, class: "IntroTitle")
      c.elements.reject { |c1| c1.name == "title" }.each do |c1|
        parse(c1, s)
      end
    end
  end
end
reference_format(b, r) click to toggle source
# File lib/isodoc/itu/ref.rb, line 54
def reference_format(b, r)
  reference_format_start(b, r)
  reference_format_title(b, r)
end
reference_format_start(b, r) click to toggle source
# File lib/isodoc/itu/ref.rb, line 101
def reference_format_start(b, r)
  id = multi_bibitem_ref_code(b)
  id1 = render_multi_identifiers(id)
  r << id1
  date = b.at(ns("./date[@type = 'published']")) and
    r << " (#{date.text.sub(/-.*$/, '')})"
  r << ", " if date || !id1.empty?
end
reference_format_title(b, r) click to toggle source
# File lib/isodoc/itu/ref.rb, line 110
def reference_format_title(b, r)
  if ftitle = b.at(ns("./formattedref"))
    ftitle&.children&.each { |n| parse(n, r) }
    /\.$/.match(ftitle&.text) or r << "."
  elsif title = iso_title(b)
    r.i do |i|
      title&.children&.each { |n| parse(n, i) }
    end
    /\.$/.match(title&.text) or r << "."
  end
end
refs_cleanup(docxml) click to toggle source
# File lib/isodoc/itu/cleanup.rb, line 42
def refs_cleanup(docxml)
  docxml.xpath("//tx[following-sibling::tx]").each do |tx|
    tx << tx.next_element.remove.children
  end
  docxml.xpath("//tx").each do |tx|
    tx.name = "td"
    tx["colspan"] = "2"
    tx.wrap("<tr></tr>")
  end
  docxml
end
render_multi_identifiers(ids) click to toggle source
# File lib/isodoc/itu/ref.rb, line 80
def render_multi_identifiers(ids)
  ids.map do |id|
    if id["type"] == "ITU"
      doctype_title(id)
    else
      docid_prefix(id["type"], id.text.sub(/^\[/, "").sub(/\]$/, ""))
    end
  end.join(" | ")
end
scope(isoxml, out, num) click to toggle source
Calls superclass method
# File lib/isodoc/itu/base_convert.rb, line 189
def scope(isoxml, out, num)
  return super unless @meta.get[:doctype_original] == "resolution"

  f = isoxml.at(ns("//clause[@type = 'scope']")) or return num
  clause_core(f, out)
  num + 1
end
std_bibitem_entry(list, b, ordinal, biblio) click to toggle source
# File lib/isodoc/itu/ref.rb, line 20
def std_bibitem_entry(list, b, ordinal, biblio)
  nonstd_bibitem(list, b, ordinal, biblio)
end
table_footnote_reference_format(node) click to toggle source
# File lib/isodoc/itu/base_convert.rb, line 161
def table_footnote_reference_format(node)
  node.content += ")"
end
term_cleanup(docxml) click to toggle source
# File lib/isodoc/itu/cleanup.rb, line 19
def term_cleanup(docxml)
  term_cleanup1(docxml)
  term_cleanup2(docxml)
  docxml
end
term_cleanup1(docxml) click to toggle source
# File lib/isodoc/itu/cleanup.rb, line 25
def term_cleanup1(docxml)
  docxml.xpath("//p[@class = 'Terms']").each do |d|
    h2 = d.at("./preceding-sibling::*[@class = 'TermNum'][1]")
    d.children.first.previous = "<b>#{h2.children.to_xml}</b>&nbsp;"
    d["id"] = h2["id"]
    h2.remove
  end
end
term_cleanup2(docxml) click to toggle source
# File lib/isodoc/itu/cleanup.rb, line 34
def term_cleanup2(docxml)
  docxml.xpath("//p[@class = 'TermNum']").each do |d|
    d1 = d.next_element and d1.name == "p" or next
    d1.children.each { |e| e.parent = d }
    d1.remove
  end
end
termdef_parse(node, out) click to toggle source
# File lib/isodoc/itu/terms.rb, line 17
def termdef_parse(node, out)
  defn = node.at(ns("./definition"))
  source = node.at(ns("./termsource/origin/@citeas"))
  out.div **attr_code(id: node["id"]) do |div|
    termdef_parse1(node, div, defn, source)
    set_termdomain("")
    node.children.each do |n|
      next if %w(preferred definition termsource title name).include? n.name
      parse(n, out)
    end
  end
end
termdef_parse1(node, div, defn, source) click to toggle source
# File lib/isodoc/itu/terms.rb, line 4
def termdef_parse1(node, div, defn, source)
  div.p **{ class: "TermNum", id: node["id"] } do |p|
    p.b do |b|
      node&.at(ns("./name"))&.children&.each { |n| parse(n, b) }
      insert_tab(b, 1)
      node&.at(ns("./preferred"))&.children&.each { |n| parse(n, b) }
    end
    p << ": "
    source and p << "#{bracket_opt(source.value)} "
  end
  defn and defn.children.each { |n| parse(n, div) }
end
termnote_delim() click to toggle source
# File lib/isodoc/itu/terms.rb, line 36
def termnote_delim
  " &ndash; "
end
title_cleanup(docxml) click to toggle source
# File lib/isodoc/itu/cleanup.rb, line 11
def title_cleanup(docxml)
  docxml.xpath("//h1[@class = 'RecommendationAnnex']").each do |h|
    h.name = "p"
    h["class"] = "h1Annex"
  end
  docxml
end
titlecase(s) click to toggle source
# File lib/isodoc/itu/ref.rb, line 59
def titlecase(s)
  s.gsub(/ |_|-/, " ").split(/ /).map(&:capitalize).join(" ")
end