Class: IsoDoc::ITU::Xref

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Xref.



7
8
9
10
# File 'lib/isodoc/itu/xref.rb', line 7

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

Instance Method Details

#annex_name_lbl(clause, num) ⇒ Object



12
13
14
15
16
# File 'lib/isodoc/itu/xref.rb', line 12

def annex_name_lbl(clause, num)
  lbl = clause["obligation"] == "informative" ? 
    @labels["appendix"] : @labels["annex"]
  l10n("<strong>#{lbl} #{num}</strong>")
end

#annex_names(clause, num) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/isodoc/itu/xref.rb', line 18

def annex_names(clause, num)
  lbl = clause["obligation"] == "informative" ? 
    @labels["appendix"] : @labels["annex"]
  @anchors[clause["id"]] =
    { label: annex_name_lbl(clause, num), type: "clause",
      xref: "#{lbl} #{num}", level: 1, value: num }
  if a = single_annex_special_section(clause)
    annex_names1(a, "#{num}", 1)
  else
    clause.xpath(ns("./clause | ./references | ./terms | ./definitions")).
      each_with_index do |c, i|
      annex_names1(c, "#{num}.#{i + 1}", 2)
    end
  end
  hierarchical_asset_names(clause, num)
end

#annex_names1(clause, num, level) ⇒ Object



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

def annex_names1(clause, num, level)
  @anchors[clause["id"]] =
    { label: num, xref: "#{@labels["annex_subclause"]} #{num}",
      level: level, type: "clause" }
  clause.xpath(ns("./clause | ./references | ./terms | ./definitions"))
    .each_with_index do |c, i|
    annex_names1(c, "#{num}.#{i + 1}", level + 1)
  end
end

#back_anchor_names(docxml) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/isodoc/itu/xref.rb', line 35

def back_anchor_names(docxml)
  super
  if annexid =
      docxml&.at(ns("//bibdata/ext/structuredidentifier/annexid"))&.text
    docxml.xpath(ns("//annex")).each { |c| annex_names(c, annexid) }
  else
    docxml.xpath(ns("//annex[@obligation = 'informative']"))
      .each_with_index do |c, i|
      annex_names(c, RomanNumerals.to_roman(i + 1))
    end
    docxml.xpath(ns("//annex[not(@obligation = 'informative')]"))
      .each_with_index do |c, i|
      annex_names(c, (65 + i + (i > 7 ? 1 : 0)).chr.to_s)
    end
  end
end

#hierarchical_figure_names(clause, num) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/isodoc/itu/xref.rb', line 111

def hierarchical_figure_names(clause, num)
  c = IsoDoc::XrefGen::Counter.new
  j = 0
  clause.xpath(ns(".//figure | "\
                  ".//sourcecode[not(ancestor::example)]")).each do |t|
    if t.parent.name == "figure" then j += 1
    else
      j = 0
      c.increment(t)
    end
    label = "#{num}#{hiersep}#{c.print}" +
      (j.zero? ? "" : "#{hierfigsep}#{(96 + j).chr.to_s}")
    next if t["id"].nil? || t["id"].empty?
    @anchors[t["id"]] = 
      anchor_struct(label, nil, @labels["figure"], "figure",
                    t["unnumbered"])
  end
end

#hierarchical_formula_names(clause, num) ⇒ Object



141
142
143
144
145
146
147
148
149
150
# File 'lib/isodoc/itu/xref.rb', line 141

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

#initial_anchor_names(d) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/isodoc/itu/xref.rb', line 62

def initial_anchor_names(d)
  d.xpath(ns("//boilerplate//clause")).each { |c| preface_names(c) }
  d.xpath("//xmlns:preface/child::*").each { |c| preface_names(c) }
  @hierarchical_assets ?
    hierarchical_asset_names(d.xpath("//xmlns:preface/child::*"), 
                             "Preface") :
                            sequential_asset_names(d.xpath("//xmlns:preface/child::*"))
  n = section_names(d.at(ns("//clause[@type = 'scope']")), 0, 1)
  n = section_names(d.at(ns(@klass.norm_ref_xpath)), n, 1)
  n = section_names(d.at(ns("//sections/terms | "\
                            "//sections/clause[descendant::terms]")), n, 1)
  n = section_names(d.at(ns("//sections/definitions")), n, 1)
  clause_names(d, n)
  middle_section_asset_names(d)
  termnote_anchor_names(d)
  termexample_anchor_names(d)
end

#middle_section_asset_names(d) ⇒ Object



88
89
90
91
92
93
# File 'lib/isodoc/itu/xref.rb', line 88

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

#middle_sectionsObject



80
81
82
83
84
85
86
# File 'lib/isodoc/itu/xref.rb', line 80

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

#reference_names(ref) ⇒ Object



152
153
154
155
156
# File 'lib/isodoc/itu/xref.rb', line 152

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

#sequential_figure_names(clause) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/isodoc/itu/xref.rb', line 95

def sequential_figure_names(clause)
  c = IsoDoc::XrefGen::Counter.new
  j = 0
  clause.xpath(ns(".//figure | .//sourcecode[not(ancestor::example)]")).each do |t|
    if t.parent.name == "figure" then j += 1
    else
      j = 0
      c.increment(t)
    end
    label = c.print + (j.zero? ? "" : "#{hierfigsep}#{(96 + j).chr.to_s}")
    next if t["id"].nil? || t["id"].empty?
    @anchors[t["id"]] =
      anchor_struct(label, nil, @labels["figure"], "figure", t["unnumbered"])
  end
end

#sequential_formula_names(clause) ⇒ Object



130
131
132
133
134
135
136
137
138
139
# File 'lib/isodoc/itu/xref.rb', line 130

def sequential_formula_names(clause)
  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

#termnote_anchor_names(docxml) ⇒ Object



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/isodoc/itu/xref.rb', line 158

def termnote_anchor_names(docxml)
  docxml.xpath(ns("//term[descendant::termnote]")).each do |t|
    c = IsoDoc::XrefGen::Counter.new
    notes = t.xpath(ns(".//termnote"))
    notes.each do |n|
      return if n["id"].nil? || n["id"].empty?
      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