class IsoDoc::BIPM::Xref

Constants

NUMBERED_SUBCLAUSES
UNNUMBERED_SUBCLAUSES

Public Class Methods

new(lang, script, klass, i18n, options = {}) click to toggle source
Calls superclass method
# File lib/isodoc/bipm/xref.rb, line 7
def initialize(lang, script, klass, i18n, options = {})
  @iso = IsoDoc::Iso::Xref.new(lang, script, klass, i18n, options)
  super
end

Public Instance Methods

annex_name_anchors(clause, num) click to toggle source
# File lib/isodoc/bipm/xref.rb, line 149
def annex_name_anchors(clause, num)
  { label: annex_name_lbl(clause, num), type: "clause", value: num.to_s,
    xref: l10n("#{@annexlbl} #{num}"), level: 1 }
end
annex_name_lbl(_clause, num) click to toggle source
# File lib/isodoc/bipm/xref.rb, line 212
def annex_name_lbl(_clause, num)
  l10n("<strong>#{@annexlbl} #{num}</strong>")
end
annex_names(clause, num) click to toggle source
# File lib/isodoc/bipm/xref.rb, line 154
def annex_names(clause, num)
  @anchors[clause["id"]] = annex_name_anchors(clause, num)
  if a = single_annex_special_section(clause)
    annex_names1(a, num.to_s, 1)
  else
    i = Counter.new
    clause.xpath(ns(NUMBERED_SUBCLAUSES)).each do |c|
      i.increment(c)
      annex_names1(c, "#{num}.#{i.print}", 2)
    end
    clause.xpath(ns(UNNUMBERED_SUBCLAUSES))
      .each { |c| unnumbered_annex_names1(c, 2) }
  end
  hierarchical_asset_names(clause, num)
end
annex_names1(clause, num, level) click to toggle source
# File lib/isodoc/bipm/xref.rb, line 193
def annex_names1(clause, num, level)
  @anchors[clause["id"]] = annex_names1_anchors(num, level)
  i = Counter.new
  clause.xpath(ns(NUMBERED_SUBCLAUSES)).each do |c|
    i.increment(c)
    annex_names1(c, "#{num}.#{i.print}", level + 1)
  end
  clause.xpath(ns(UNNUMBERED_SUBCLAUSES))
    .each { |c| unnumbered_annex_names1(c, level + 1) }
end
annex_names1_anchors(num, level) click to toggle source
# File lib/isodoc/bipm/xref.rb, line 187
def annex_names1_anchors(num, level)
  lbl = @jcgm ? "" : "#{@annexlbl} "
  { label: num, xref: l10n("#{lbl}#{num}"),
    level: level, type: "clause" }
end
back_anchor_names(docxml) click to toggle source
Calls superclass method
# File lib/isodoc/bipm/xref.rb, line 137
def back_anchor_names(docxml)
  super
  i = @jcgm ? Counter.new("@", skip_i: true) : Counter.new(0)
  docxml.xpath(ns("//annex[not(@unnumbered = 'true')]")).each do |c|
    i.increment(c)
    annex_names(c, i.print)
  end
  docxml.xpath(ns("//annex[@unnumbered = 'true']"))
    .each { |c| unnumbered_annex_names(c) }
  docxml.xpath(ns("//indexsect")).each { |b| preface_names(b) }
end
clause_names(docxml, sect_num) click to toggle source
# File lib/isodoc/bipm/xref.rb, line 36
def clause_names(docxml, sect_num)
  if @jcgm
    clause_names_jcgm(docxml, sect_num)
  else
    clause_names_bipm(docxml, sect_num)
  end
end
clause_names_bipm(docxml, _sect_num) click to toggle source
# File lib/isodoc/bipm/xref.rb, line 51
def clause_names_bipm(docxml, _sect_num)
  n = Counter.new
  docxml.xpath(ns("//sections/clause[not(@unnumbered = 'true')] | "\
                  "//sections/terms[not(@unnumbered = 'true')] | "\
                  "//sections/definitions[not(@unnumbered = 'true')]"))
    .each { |c| section_names(c, n, 1) }
  docxml.xpath(ns("//sections/clause[@unnumbered = 'true'] | "\
                  "//sections/terms[@unnumbered = 'true'] | "\
                  "//sections/definitions[@unnumbered = 'true']"))
    .each { |c| unnumbered_section_names(c, 1) }
end
clause_names_jcgm(docxml, sect_num) click to toggle source
# File lib/isodoc/bipm/xref.rb, line 44
def clause_names_jcgm(docxml, sect_num)
  docxml.xpath(ns("//clause[parent::sections][not(@type = 'scope')]"\
                  "[not(descendant::terms)]")).each do |c|
    section_names(c, sect_num, 1)
  end
end
hierarchical_figure_names(clause, num) click to toggle source
Calls superclass method
# File lib/isodoc/bipm/xref.rb, line 245
def hierarchical_figure_names(clause, num)
  if @jcgm
    @iso.hierarchical_figure_names(clause, num)
    @anchors.merge!(@iso.get)
  else super
  end
end
initial_anchor_names(doc) click to toggle source
Calls superclass method
# File lib/isodoc/bipm/xref.rb, line 229
def initial_anchor_names(doc)
  super
  if @jcgm
    @iso.introduction_names(doc.at(ns("//introduction")))
    @anchors.merge!(@iso.get)
  end
end
parse(docxml) click to toggle source
Calls superclass method
# File lib/isodoc/bipm/xref.rb, line 12
def parse(docxml)
  @jcgm = docxml&.at(ns("//bibdata/ext/editorialgroup/committee/"\
                        "@acronym"))&.value == "JCGM"
  @annexlbl =
    if @jcgm then @labels["iso_annex"]
    elsif docxml.at(ns("//bibdata/ext/structuredidentifier/appendix"))
      @labels["appendix"]
    else @labels["annex"]
    end
  super
end
reference_names(ref) click to toggle source
Calls superclass method
# File lib/isodoc/bipm/xref.rb, line 30
def reference_names(ref)
  super
  @jcgm and
    @anchors[ref["id"]][:xref] = wrap_brackets(@anchors[ref["id"]][:xref])
end
section_name1_anchors(clause, num, level) click to toggle source
# File lib/isodoc/bipm/xref.rb, line 109
def section_name1_anchors(clause, num, level)
  lbl = @jcgm ? "" : "#{@labels['subclause']} "
  @anchors[clause["id"]] =
    { label: num, level: level, xref: l10n("#{lbl}#{num}"),
      type: "clause" }
end
section_name_anchors(clause, num, lvl) click to toggle source
# File lib/isodoc/bipm/xref.rb, line 75
def section_name_anchors(clause, num, lvl)
  lbl = @jcgm ? "clause_jcgm" : "clause"
  @anchors[clause["id"]] =
    { label: num.print, xref: l10n("#{@labels[lbl]} #{num.print}"),
      level: lvl, type: "clause" }
end
section_names(clause, num, lvl) click to toggle source
# File lib/isodoc/bipm/xref.rb, line 82
def section_names(clause, num, lvl)
  return num if clause.nil?

  num.increment(clause)
  @anchors[clause["id"]] = section_name_anchors(clause, num, lvl)
  i = Counter.new
  clause.xpath(ns(NUMBERED_SUBCLAUSES)).each do |c|
    i.increment(c)
    section_names1(c, "#{num.print}.#{i.print}", lvl + 1)
  end
  clause.xpath(ns(UNNUMBERED_SUBCLAUSES)).each do |c|
    unnumbered_section_names1(c, lvl + 1)
  end
  num
end
section_names1(clause, num, level) click to toggle source
# File lib/isodoc/bipm/xref.rb, line 116
def section_names1(clause, num, level)
  @anchors[clause["id"]] = section_name1_anchors(clause, num, level)
  i = Counter.new
  clause.xpath(ns(NUMBERED_SUBCLAUSES)).each do |c|
    i.increment(c)
    section_names1(c, "#{num}.#{i.print}", level + 1)
  end
  clause.xpath(ns(UNNUMBERED_SUBCLAUSES)).each do |c|
    unnumbered_section_names1(c, lvl + 1)
  end
end
sequential_figure_names(clause) click to toggle source
Calls superclass method
# File lib/isodoc/bipm/xref.rb, line 237
def sequential_figure_names(clause)
  if @jcgm
    @iso.sequential_figure_names(clause)
    @anchors.merge!(@iso.get)
  else super
  end
end
sequential_formula_names(clause) click to toggle source
# File lib/isodoc/bipm/xref.rb, line 216
def sequential_formula_names(clause)
  c = Counter.new
  clause.xpath(ns(".//formula")).each do |t|
    next if t["id"].nil? || t["id"].empty?

    @anchors[t["id"]] = anchor_struct(
      c.increment(t).print, nil,
      t["inequality"] ? @labels["inequality"] : @labels["formula"],
      "formula", t["unnumbered"]
    )
  end
end
unnumbered_annex_anchors(lbl) click to toggle source
# File lib/isodoc/bipm/xref.rb, line 170
def unnumbered_annex_anchors(lbl)
  { label: lbl, type: "clause", value: "",
    xref: l10n(%{"#{lbl}"}), level: 1 }
end
unnumbered_annex_names(clause) click to toggle source
# File lib/isodoc/bipm/xref.rb, line 175
def unnumbered_annex_names(clause)
  lbl = clause&.at(ns("./title"))&.text || "[#{clause['id']}]"
  @anchors[clause["id"]] = unnumbered_annex_anchors(lbl)
  if a = single_annex_special_section(clause)
    annex_names1(a, num.to_s, 1)
  else
    clause.xpath(ns(SUBCLAUSES))
      .each { |c| unnumbered_annex_names1(c, 2) }
  end
  hierarchical_asset_names(clause, lbl)
end
unnumbered_annex_names1(clause, level) click to toggle source
# File lib/isodoc/bipm/xref.rb, line 204
def unnumbered_annex_names1(clause, level)
  lbl = clause&.at(ns("./title"))&.text || "[#{clause['id']}]"
  @anchors[clause["id"]] = { label: lbl, xref: l10n(%{"#{lbl}"}),
                             level: level, type: "clause" }
  clause.xpath(ns(SUBCLAUSES))
    .each { |c| unnumbered_annex_names1(c, level + 1) }
end
unnumbered_section_names(clause, lvl) click to toggle source
# File lib/isodoc/bipm/xref.rb, line 98
def unnumbered_section_names(clause, lvl)
  return if clause.nil?

  lbl = clause&.at(ns("./title"))&.text || "[#{clause['id']}]"
  @anchors[clause["id"]] = { label: lbl, xref: l10n(%{"#{lbl}"}),
                             level: lvl, type: "clause" }
  clause.xpath(ns(SUBCLAUSES)).each do |c|
    unnumbered_section_names1(c, lvl + 1)
  end
end
unnumbered_section_names1(clause, level) click to toggle source
# File lib/isodoc/bipm/xref.rb, line 128
def unnumbered_section_names1(clause, level)
  lbl = clause&.at(ns("./title"))&.text || "[#{clause['id']}]"
  @anchors[clause["id"]] =
    { label: lbl, xref: l10n(%{"#{lbl}"}), level: level, type: "clause" }
  clause.xpath(ns(SUBCLAUSES)).each do |c|
    unnumbered_section_names1(c, level + 1)
  end
end
wrap_brackets(txt) click to toggle source
# File lib/isodoc/bipm/xref.rb, line 24
def wrap_brackets(txt)
  return txt if /^\[.*\]$/.match?(txt)

  "[#{txt}]"
end