Class: IsoDoc::ITU::Xref
- Inherits:
-
Xref
- Object
- Xref
- IsoDoc::ITU::Xref
- Defined in:
- lib/isodoc/itu/xref.rb
Instance Method Summary collapse
- #annex_name_lbl(clause, num) ⇒ Object
- #annex_names(clause, num) ⇒ Object
- #annex_names1(clause, num, level) ⇒ Object
- #back_anchor_names(docxml) ⇒ Object
- #clause_names(docxml, sect_num) ⇒ Object
- #hierarchical_figure_names(clause, num) ⇒ Object
- #hierarchical_formula_names(clause, num) ⇒ Object
- #initial_anchor_names(d) ⇒ Object
-
#initialize(lang, script, klass, labels, options) ⇒ Xref
constructor
A new instance of Xref.
- #middle_section_asset_names(d) ⇒ Object
- #middle_sections ⇒ Object
- #reference_names(ref) ⇒ Object
- #section_names(clause, num, lvl) ⇒ Object
- #section_names1(clause, num, level) ⇒ Object
- #sequential_figure_names(clause) ⇒ Object
- #sequential_formula_names(clause) ⇒ Object
- #termnote_anchor_names(docxml) ⇒ Object
- #unnumbered_section_names(clause, lvl) ⇒ Object
- #unnumbered_section_names1(clause, level) ⇒ Object
Constructor Details
#initialize(lang, script, klass, labels, options) ⇒ Xref
Returns a new instance of Xref.
14 15 16 17 |
# File 'lib/isodoc/itu/xref.rb', line 14 def initialize(lang, script, klass, labels, ) super @hierarchical_assets = [:hierarchical_assets] end |
Instance Method Details
#annex_name_lbl(clause, num) ⇒ Object
19 20 21 22 23 |
# File 'lib/isodoc/itu/xref.rb', line 19 def annex_name_lbl(clause, num) lbl = clause["obligation"] == "informative" ? @labels["appendix"] : @labels["annex"] @doctype == "resolution" ? l10n("#{lbl.upcase} #{num}") : l10n("<strong>#{lbl} #{num}</strong>") end |
#annex_names(clause, num) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/isodoc/itu/xref.rb', line 25 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: l10n("#{lbl} #{num}"), level: 1, value: num } if a = single_annex_special_section(clause) annex_names1(a, "#{num}", 1) else i = Counter.new clause.xpath(ns("./clause | ./references | ./terms | ./definitions")). each do |c| i.increment(c) annex_names1(c, "#{num}.#{i.print}", 2) end end hierarchical_asset_names(clause, num) end |
#annex_names1(clause, num, level) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/isodoc/itu/xref.rb', line 64 def annex_names1(clause, num, level) @anchors[clause["id"]] = { label: num, xref: @doctype == "resolution" ? num : l10n("#{@labels["annex_subclause"]} #{num}"), level: level, type: "clause" } i = Counter.new clause.xpath(ns("./clause | ./references | ./terms | ./definitions")) .each do |c| i.increment(c) annex_names1(c, "#{num}.#{i.print}", level + 1) end end |
#back_anchor_names(docxml) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/isodoc/itu/xref.rb', line 43 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 i = Counter.new(0, numerals: :roman) docxml.xpath(ns("//annex[@obligation = 'informative']")) .each_with_index do |c| i.increment(c) annex_names(c, i.print.upcase) end i = Counter.new("@") docxml.xpath(ns("//annex[not(@obligation = 'informative')]")) .each do |c| i.increment(c) i.increment(c) if i.print == "I" annex_names(c, i.print) end end end |
#clause_names(docxml, sect_num) ⇒ Object
179 180 181 182 183 184 185 186 187 |
# File 'lib/isodoc/itu/xref.rb', line 179 def clause_names(docxml, sect_num) docxml.xpath(ns("//sections/clause[not(@unnumbered = 'true')][not(@type = 'scope')][not(descendant::terms)]")). each do |c| section_names(c, sect_num, 1) end docxml.xpath(ns("//sections/clause[@unnumbered = 'true']")).each do |c| unnumbered_section_names(c, 1) end end |
#hierarchical_figure_names(clause, num) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/isodoc/itu/xref.rb', line 125 def hierarchical_figure_names(clause, num) c = 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
150 151 152 153 154 155 156 157 158 |
# File 'lib/isodoc/itu/xref.rb', line 150 def hierarchical_formula_names(clause, num) c = 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
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/isodoc/itu/xref.rb', line 76 def initial_anchor_names(d) @doctype = d&.at(ns("//bibdata/ext/doctype"))&.text 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 = Counter.new n = section_names(d.at(ns("//clause[@type = 'scope']")), n, 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
103 104 105 106 107 108 |
# File 'lib/isodoc/itu/xref.rb', line 103 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_sections ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/isodoc/itu/xref.rb', line 95 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
160 161 162 163 |
# File 'lib/isodoc/itu/xref.rb', line 160 def reference_names(ref) super @anchors[ref["id"]] = { xref: @anchors[ref["id"]][:xref].sub(/^\[/, '').sub(/\]$/, '') } end |
#section_names(clause, num, lvl) ⇒ Object
189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/isodoc/itu/xref.rb', line 189 def section_names(clause, num, lvl) return num if clause.nil? 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" } i = Counter.new() clause.xpath(ns(SUBCLAUSES)).each do |c| i.increment(c) section_names1(c, "#{num.print}.#{i.print}", lvl + 1) end num end |
#section_names1(clause, num, level) ⇒ Object
203 204 205 206 207 208 209 210 211 212 |
# File 'lib/isodoc/itu/xref.rb', line 203 def section_names1(clause, num, level) @anchors[clause["id"]] = { label: num, level: level, xref: @doctype == "resolution" ? num : l10n("#{@labels["clause"]} #{num}") } i = Counter.new() clause.xpath(ns(SUBCLAUSES)).each do |c| i.increment(c) section_names1(c, "#{num}.#{i.print}", level + 1) end end |
#sequential_figure_names(clause) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/isodoc/itu/xref.rb', line 110 def sequential_figure_names(clause) c = 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
140 141 142 143 144 145 146 147 148 |
# File 'lib/isodoc/itu/xref.rb', line 140 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
165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/isodoc/itu/xref.rb', line 165 def termnote_anchor_names(docxml) docxml.xpath(ns("//term[descendant::termnote]")).each do |t| c = 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 |
#unnumbered_section_names(clause, lvl) ⇒ Object
214 215 216 217 218 219 220 221 222 |
# File 'lib/isodoc/itu/xref.rb', line 214 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) ⇒ Object
224 225 226 227 228 229 230 231 |
# File 'lib/isodoc/itu/xref.rb', line 224 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 |