Class: IsoDoc::Itu::Xref
- Inherits:
-
Xref
- Object
- Xref
- IsoDoc::Itu::Xref
- Defined in:
- lib/isodoc/itu/xref.rb,
lib/isodoc/itu/xref_section.rb
Instance Method Summary collapse
- #annex_anchor_names(xml) ⇒ Object
- #annex_name_anchors(clause, num, level) ⇒ Object
- #annex_name_anchors1(clause, lbl, level) ⇒ Object
- #annex_name_lbl(clause, num) ⇒ Object
- #annex_names_with_counter(docxml, xpath, counter) ⇒ Object
- #annextype(clause) ⇒ Object
- #asset_anchor_names(doc) ⇒ Object
- #clause_order_annex(docxml) ⇒ Object
- #clause_order_preface(_docxml) ⇒ Object
- #fig_subfig_label(label, sublabel) ⇒ Object
- #figure_anchor(elem, sublabel, label, klass, container: false) ⇒ Object
- #hierarchical_formula_names(clause, num) ⇒ Object
-
#initialize(lang, script, klass, labels, options) ⇒ Xref
constructor
A new instance of Xref.
- #main_anchor_names(xml) ⇒ Object
- #middle_section_asset_names(doc) ⇒ Object
- #middle_sections ⇒ Object
- #section_names(clause, num, lvl) ⇒ Object
- #section_names1(clause, parentnum, num, level) ⇒ Object
- #sequential_formula_names(clause, container: false) ⇒ Object
- #subfigure_anchor(elem, sublabel, label, klass, container: false) ⇒ Object
- #subfigure_delim ⇒ Object
- #subfigure_label(subfignum) ⇒ 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.
36 37 38 39 |
# File 'lib/isodoc/itu/xref.rb', line 36 def initialize(lang, script, klass, labels, ) super @hierarchical_assets = [: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
57 58 59 60 61 62 63 64 |
# File 'lib/isodoc/itu/xref_section.rb', line 57 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: labelled_autonum(lbl, num) } end |
#annex_name_anchors1(clause, lbl, level) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/isodoc/itu/xref_section.rb', line 66 def annex_name_anchors1(clause, lbl, level) xref = labelled_autonum(@labels["annex_subclause"], lbl) @doctype == "resolution" and xref = lbl @anchors[clause["id"]] = { label: lbl, elem: @labels["annex_subclause"], xref: xref, level: level, type: "clause" } end |
#annex_name_lbl(clause, num) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/isodoc/itu/xref_section.rb', line 44 def annex_name_lbl(clause, num) lbl = annextype(clause) if @doctype == "resolution" l10n("<span class='fmt-element-name'>#{lbl.upcase}</span> #{semx( clause, num )}") else l10n("<strong><span class='fmt-caption-label'><span class='fmt-element-name'>#{lbl}</span> #{semx( clause, num )}</span></strong>") 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
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/isodoc/itu/xref.rb', line 49 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/*/clause", multi: true }, { path: "//preface/*", multi: true }] end |
#fig_subfig_label(label, sublabel) ⇒ Object
88 89 90 |
# File 'lib/isodoc/itu/xref.rb', line 88 def fig_subfig_label(label, sublabel) "#{label}#{delim_wrap("-")}#{sublabel}" end |
#figure_anchor(elem, sublabel, label, klass, container: false) ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/isodoc/itu/xref.rb', line 77 def figure_anchor(elem, sublabel, label, klass, container: false) if sublabel subfigure_anchor(elem, sublabel, label, klass, container: false) else @anchors[elem["id"]] = anchor_struct( label, elem, @labels[klass] || klass.capitalize, klass, { unnumb: elem["unnumbered"], container: } ) end end |
#hierarchical_formula_names(clause, num) ⇒ Object
118 119 120 121 122 123 124 125 126 127 |
# File 'lib/isodoc/itu/xref.rb', line 118 def hierarchical_formula_names(clause, num) c = Counter.new clause.xpath(ns(".//formula")).noblank.each do |t| @anchors[t["id"]] = anchor_struct( "#{semx(clause, num)}#{delim_wrap("-")}#{semx(t, c.increment(t).print)}", t, t["inequality"] ? @labels["inequality"] : @labels["formula"], "formula", { unnumb: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
61 62 63 64 65 66 |
# File 'lib/isodoc/itu/xref.rb', line 61 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_sections ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/isodoc/itu/xref.rb', line 41 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 |
#section_names(clause, num, lvl) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# 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) elem = @doctype == "resolution" ? @labels["section"] : @labels["clause"] lbl = semx(clause, num.print) @anchors[clause["id"]] = { label: lbl, xref: labelled_autonum(elem, lbl), level: lvl, type: "clause", elem: elem } i = Counter.new(0) clause.xpath(ns(SUBCLAUSES)).each do |c| section_names1(c, lbl, i.increment(c).print, lvl + 1) end num end |
#section_names1(clause, parentnum, num, level) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/isodoc/itu/xref_section.rb', line 103 def section_names1(clause, parentnum, num, level) lbl = clause_number_semx(parentnum, clause, num) x = @doctype == "resolution" ? semx(clause, lbl) : labelled_autonum(@labels["clause"], lbl) # l10n("#{@labels['clause']} #{num}") @anchors[clause["id"]] = { label: lbl, level: level, elem: @doctype == "resolution" ? "" : @labels["clause"], xref: x } i = Counter.new(0) clause.xpath(ns(SUBCLAUSES)).each do |c| section_names1(c, lbl, i.increment(c).print, level + 1) end end |
#sequential_formula_names(clause, container: false) ⇒ Object
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/isodoc/itu/xref.rb', line 107 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_anchor(elem, sublabel, label, klass, container: false) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/isodoc/itu/xref.rb', line 92 def subfigure_anchor(elem, sublabel, label, klass, container: false) figlabel = fig_subfig_label(semx(elem.parent, label), semx(elem, sublabel)) @anchors[elem["id"]] = anchor_struct( figlabel, elem, @labels[klass] || klass.capitalize, klass, { unnumb: elem["unnumbered"] } ) if elem["unnumbered"] != "true" #@anchors[elem["id"]][:label] = sublabel @anchors[elem["id"]][:xref] = @anchors[elem.parent["id"]][:xref] + delim_wrap("-") + semx(elem, sublabel) x = @anchors[elem.parent["id"]][:container] and @anchors[elem["id"]][:container] = x end end |
#subfigure_delim ⇒ Object
73 74 75 |
# File 'lib/isodoc/itu/xref.rb', line 73 def subfigure_delim ")" end |
#subfigure_label(subfignum) ⇒ Object
68 69 70 71 |
# File 'lib/isodoc/itu/xref.rb', line 68 def subfigure_label(subfignum) subfignum.zero? and return (subfignum + 96).chr end |
#termnote_anchor_names(docxml) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/isodoc/itu/xref.rb', line 129 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 idx.blank? or notenum = " #{semx(n, idx)}" @anchors[n["id"]] = { label: termnote_label(n, idx).strip, type: "termnote", value: idx, xref: l10n("#{semx(t, anchor(t['id'], :xref))}<span class='fmt-comma'>,</span> <span class='fmt-element-name'>#{@labels['note_xref']}</span>#{notenum}") } end end end |
#unnumbered_section_names(clause, lvl) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/isodoc/itu/xref_section.rb', line 116 def unnumbered_section_names(clause, lvl) clause.nil? and return lbl = clause.at(ns("./title"))&.text || "[#{clause['id']}]" @anchors[clause["id"]] = { label: lbl, xref: semx(clause, 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
129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/isodoc/itu/xref_section.rb', line 129 def unnumbered_section_names1(clause, level) lbl = clause&.at(ns("./title"))&.text || "[#{clause['id']}]" @anchors[clause["id"]] = { label: lbl, xref: semx(clause, lbl), level: level, type: "clause" } clause.xpath(ns(SUBCLAUSES)).each do |c| unnumbered_section_names1(c, level + 1) end end |