Class: IsoDoc::ITU::Xref

Inherits:
Xref
  • Object
show all
Defined in:
lib/isodoc/itu/xref.rb,
lib/isodoc/itu/xref_section.rb

Instance Method Summary collapse

Constructor Details

#initialize(lang, script, klass, labels, options) ⇒ Xref

Returns a new instance of Xref.



18
19
20
21
# File 'lib/isodoc/itu/xref.rb', line 18

def initialize(lang, script, klass, labels, options)
  super
  @hierarchical_assets = options[:hierarchicalassets]
end

Instance Method Details

#annex_anchor_names(xml) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/isodoc/itu/xref_section.rb', line 13

def annex_anchor_names(xml)
  t = clause_order_annex(xml)
  if annexid = xml.at(ns("//bibdata/ext/structuredidentifier/annexid"))
    xml.xpath(ns(t[0][:path])).each do |c|
      annex_names(c, annexid.text)
    end
  else
    annex_names_with_counter(xml, t[0][:path],
                             Counter.new("@", skip_i: true))
    annex_names_with_counter(xml, t[1][:path],
                             Counter.new(0, numerals: :roman))
  end
end

#annex_name_anchors(clause, num, level) ⇒ Object



53
54
55
56
57
58
59
60
# File 'lib/isodoc/itu/xref_section.rb', line 53

def annex_name_anchors(clause, num, level)
  lbl = annextype(clause)
  @anchors[clause["id"]] =
    { label: annex_name_lbl(clause, num),
      elem: lbl,
      type: "clause", value: num.to_s, level: level,
      xref: l10n("#{lbl} #{num}") }
end

#annex_name_lbl(clause, num) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/isodoc/itu/xref_section.rb', line 44

def annex_name_lbl(clause, num)
  lbl = annextype(clause)
  if @doctype == "resolution"
    l10n("#{lbl.upcase} #{num}")
  else
    l10n("<strong>#{lbl} #{num}</strong>")
  end
end

#annex_names1(clause, num, level) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/isodoc/itu/xref_section.rb', line 62

def annex_names1(clause, num, level)
  @anchors[clause["id"]] =
    { label: num, elem: @labels["annex_subclause"],
      xref: @doctype == "resolution" ? num : l10n("#{@labels['annex_subclause']} #{num}"),
      level: level, type: "clause" }
  i = Counter.new(0, prefix: "#{num}.")
  clause.xpath(ns("./clause | ./references | ./terms | ./definitions"))
    .each do |c|
    annex_names1(c, i.increment(c).print, level + 1)
  end
end

#annex_names_with_counter(docxml, xpath, counter) ⇒ Object



27
28
29
30
31
# File 'lib/isodoc/itu/xref_section.rb', line 27

def annex_names_with_counter(docxml, xpath, counter)
  docxml.xpath(ns(xpath)).each do |c|
    annex_names(c, counter.increment(c).print.upcase)
  end
end

#annextype(clause) ⇒ Object



38
39
40
41
42
# File 'lib/isodoc/itu/xref_section.rb', line 38

def annextype(clause)
  if clause["obligation"] == "informative" then @labels["appendix"]
  else @labels["annex"]
  end
end

#asset_anchor_names(doc) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/isodoc/itu/xref.rb', line 31

def asset_anchor_names(doc)
  super
  if @parse_settings.empty?
    if @hierarchical_assets
      hierarchical_asset_names(doc.xpath("//xmlns:preface/child::*"),
                               "Preface")
    else
      sequential_asset_names(doc.xpath("//xmlns:preface/child::*"))
    end
  end
end

#clause_order_annex(docxml) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/isodoc/itu/xref_section.rb', line 4

def clause_order_annex(docxml)
  if docxml.at(ns("//bibdata/ext/structuredidentifier/annexid"))
    [{ path: "//annex", multi: true }]
  else
    [{ path: "//annex[not(@obligation = 'informative')]", multi: true },
     { path: "//annex[@obligation = 'informative']", multi: true }]
  end
end

#clause_order_preface(_docxml) ⇒ Object



33
34
35
36
# File 'lib/isodoc/itu/xref_section.rb', line 33

def clause_order_preface(_docxml)
  [{ path: "//boilerplate/*", multi: true },
   { path: "//preface/*", multi: true }]
end

#hierarchical_figure_body(num, subfignum, counter, block, klass) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/isodoc/itu/xref.rb', line 64

def hierarchical_figure_body(num, subfignum, counter, block, klass)
  label = "#{num}#{hiersep}#{counter.print}" + subfigure_label(subfignum)
  @anchors[block["id"]] = anchor_struct(
    label, nil, @labels[klass] || klass.capitalize,
    klass, block["unnumbered"]
  )
end

#hierarchical_formula_names(clause, num) ⇒ Object



83
84
85
86
87
88
89
90
91
92
# File 'lib/isodoc/itu/xref.rb', line 83

def hierarchical_formula_names(clause, num)
  c = Counter.new
  clause.xpath(ns(".//formula")).noblank.each do |t|
    @anchors[t["id"]] = anchor_struct(
      "#{num}-#{c.increment(t).print}", nil,
      t["inequality"] ? @labels["inequality"] : @labels["formula"],
      "formula", t["unnumbered"]
    )
  end
end

#main_anchor_names(xml) ⇒ Object



74
75
76
77
78
79
80
81
82
# File 'lib/isodoc/itu/xref_section.rb', line 74

def main_anchor_names(xml)
  n = Counter.new
  clause_order_main(xml).each do |a|
    xml.xpath(ns(a[:path])).each do |c|
      section_names(c, n, 1)
      a[:multi] or break
    end
  end
end

#middle_section_asset_names(doc) ⇒ Object



43
44
45
46
47
48
# File 'lib/isodoc/itu/xref.rb', line 43

def middle_section_asset_names(doc)
  @hierarchical_assets or return super
  doc.xpath(ns(middle_sections)).each do |c|
    hierarchical_asset_names(c, @anchors[c["id"]][:label])
  end
end

#middle_sectionsObject



23
24
25
26
27
28
29
# File 'lib/isodoc/itu/xref.rb', line 23

def middle_sections
  "//clause[@type = 'scope'] | //preface/abstract | " \
    "//foreword | //introduction | //acknowledgements |  " \
    "#{@klass.norm_ref_xpath} | " \
    "//sections/terms | //preface/clause | " \
    "//sections/definitions | //clause[parent::sections]"
end

#reference_names(ref) ⇒ Object



94
95
96
97
98
# File 'lib/isodoc/itu/xref.rb', line 94

def reference_names(ref)
  super
  @anchors[ref["id"]] =
    { xref: @anchors[ref["id"]][:xref].sub(/^\[/, "").sub(/\]$/, "") }
end

#section_names(clause, num, lvl) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/isodoc/itu/xref_section.rb', line 84

def section_names(clause, num, lvl)
  clause.nil? and return num
  clause["unnumbered"] == "true" and return unnumbered_section_names(
    clause, 1
  )

  num.increment(clause)
  lbl = @doctype == "resolution" ? @labels["section"] : @labels["clause"]
  @anchors[clause["id"]] =
    { label: num.print, xref: l10n("#{lbl} #{num.print}"),
      level: lvl, type: "clause", elem: lbl }
  i = Counter.new(0, prefix: "#{num.print}.")
  clause.xpath(ns(SUBCLAUSES)).each do |c|
    section_names1(c, i.increment(c).print, lvl + 1)
  end
  num
end

#section_names1(clause, num, level) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
# File 'lib/isodoc/itu/xref_section.rb', line 102

def section_names1(clause, num, level)
  x = @doctype == "resolution" ? num : l10n("#{@labels['clause']} #{num}")
  @anchors[clause["id"]] =
    { label: num, level: level,
      elem: @doctype == "resolution" ? "" : @labels["clause"],
      xref: x }
  i = Counter.new(0, prefix: "#{num}.")
  clause.xpath(ns(SUBCLAUSES)).each do |c|
    section_names1(c, i.increment(c).print, level + 1)
  end
end

#sequential_figure_body(subfig, counter, elem, klass, container: false) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/isodoc/itu/xref.rb', line 55

def sequential_figure_body(subfig, counter, elem, klass, container: false)
  label = counter.print
  label &&= label + subfigure_label(subfig)
  @anchors[elem["id"]] = anchor_struct(
    label, container ? elem : nil, @labels[klass] || klass.capitalize,
    klass, elem["unnumbered"]
  )
end

#sequential_formula_names(clause, container: false) ⇒ Object



72
73
74
75
76
77
78
79
80
81
# File 'lib/isodoc/itu/xref.rb', line 72

def sequential_formula_names(clause, container: false)
  clause.first&.xpath(ns(middle_sections))&.each do |c|
    if c["id"] && @anchors[c["id"]]
      hierarchical_formula_names(c, @anchors[c["id"]][:label] ||
                                 @anchors[c["id"]][:xref] || "???")
    else
      hierarchical_formula_names(c, "???")
    end
  end
end

#subfigure_label(subfignum) ⇒ Object



50
51
52
53
# File 'lib/isodoc/itu/xref.rb', line 50

def subfigure_label(subfignum)
  subfignum.zero? and return ""
  "-#{(subfignum + 96).chr}"
end

#termnote_anchor_names(docxml) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/isodoc/itu/xref.rb', line 100

def termnote_anchor_names(docxml)
  docxml.xpath(ns("//term[termnote]")).each do |t|
    c = Counter.new
    notes = t.xpath(ns("./termnote"))
    notes.noblank.each do |n|
      idx = notes.size == 1 ? "" : " #{c.increment(n).print}"
      @anchors[n["id"]] =
        { label: termnote_label(idx).strip, type: "termnote", value: idx,
          xref: l10n("#{anchor(t['id'], :xref)},
                     #{@labels['note_xref']} #{c.print}") }
    end
  end
end

#unnumbered_section_names(clause, lvl) ⇒ Object



114
115
116
117
118
119
120
121
122
123
# File 'lib/isodoc/itu/xref_section.rb', line 114

def unnumbered_section_names(clause, lvl)
  clause.nil? and return
  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) ⇒ Object



125
126
127
128
129
130
131
132
133
# File 'lib/isodoc/itu/xref_section.rb', line 125

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