Class: IsoDoc::UN::Xref
- Inherits:
-
Xref
- Object
- Xref
- IsoDoc::UN::Xref
- Defined in:
- lib/isodoc/un/xref.rb
Constant Summary collapse
- NONTERMINAL =
"./clause | ./term | ./terms | ./definitions | ./references".freeze
- SUBCLAUSES =
"./clause | ./references | ./term | ./terms | ./definitions".freeze
Instance Method Summary collapse
- #annex_anchor_names(xml) ⇒ Object
- #annex_levelnum(num, lvl) ⇒ Object
- #annex_name_anchors(clause, num) ⇒ Object
- #annex_name_lbl(_clause, num) ⇒ Object
- #annex_names(clause, number) ⇒ Object
- #annex_names1(clause, num, level) ⇒ Object
- #asset_anchor_names(doc) ⇒ Object
- #clause_order_back(_docxml) ⇒ Object
- #clause_order_main(_docxml) ⇒ Object
- #hierarchical_admonition_names(clause, num) ⇒ Object
- #hierarchical_asset_names(clause, num) ⇒ Object
- #label_annex_leaf_section(clause, num, lvl) ⇒ Object
- #label_leaf_section(clause, lvl) ⇒ Object
- #leaf_section?(clause) ⇒ Boolean
- #levelnumber(num, lvl) ⇒ Object
- #main_anchor_names(xml) ⇒ Object
- #section_names(clause, num, lvl) ⇒ Object
- #section_names1(clause, num, level) ⇒ Object
- #sequential_admonition_names(clause, container: false) ⇒ Object
- #sequential_asset_names(clause, container: false) ⇒ Object
Instance Method Details
#annex_anchor_names(xml) ⇒ Object
95 96 97 98 99 100 101 102 103 |
# File 'lib/isodoc/un/xref.rb', line 95 def annex_anchor_names(xml) i = ::IsoDoc::XrefGen::Counter.new clause_order_annex(xml).each do |a| xml.xpath(ns(a[:path])).each do |c| annex_names(c, i.increment(c).print) a[:multi] or break end end end |
#annex_levelnum(num, lvl) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/isodoc/un/xref.rb', line 32 def annex_levelnum(num, lvl) case lvl % 3 when 0 then RomanNumerals.to_roman(num.to_i) when 1 then ("A".ord + num.to_i - 1).chr when 2 then num.to_s end end |
#annex_name_anchors(clause, num) ⇒ Object
112 113 114 115 116 117 |
# File 'lib/isodoc/un/xref.rb', line 112 def annex_name_anchors(clause, num) { label: annex_name_lbl(clause, num), elem: @labels["annex"], type: "clause", value: num.to_s, level: 1, xref: "#{@labels['annex']} #{num}" } end |
#annex_name_lbl(_clause, num) ⇒ Object
105 106 107 |
# File 'lib/isodoc/un/xref.rb', line 105 def annex_name_lbl(_clause, num) l10n("<strong>#{@labels['annex']} #{num}</strong>") end |
#annex_names(clause, number) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/isodoc/un/xref.rb', line 119 def annex_names(clause, number) @paranumber = 0 num = annex_levelnum(number, 0) hierarchical_asset_names(clause, num) leaf_section?(clause) and label_annex_leaf_section(clause, num, 1) and return @anchors[clause["id"]] = annex_name_anchors(clause, num) if @klass.single_term_clause?(clause) annex_names1(clause.at(ns("./references | ./terms | ./definitions")), num.to_s, 1) else i = 1 clause.xpath(ns(SUBCLAUSES)).each do |c| c["unnumbered"] == "true" and next annex_names1(c, "#{num}.#{annex_levelnum(i, 2)}", 2) i += 1 if !leaf_section?(c) end end end |
#annex_names1(clause, num, level) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/isodoc/un/xref.rb', line 139 def annex_names1(clause, num, level) leaf_section?(clause) and label_annex_leaf_section(clause, num, level) and return /\.(?<leafnum>[^.]+$)/ =~ num @anchors[clause["id"]] = { label: leafnum, xref: l10n("#{@labels['annex']} #{num}"), level: level, type: "clause", elem: @labels["annex"] } i = 1 clause.xpath(ns("./clause | ./references")).each do |c| c["unnumbered"] == "true" and next annex_names1(c, "#{num}.#{annex_levelnum(i, level + 1)}", level + 1) i += 1 if !leaf_section?(c) end end |
#asset_anchor_names(doc) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/isodoc/un/xref.rb', line 10 def asset_anchor_names(doc) super @parse_settings.empty? or return sequential_asset_names( doc.xpath(ns("//preface/abstract | //foreword | //introduction | " \ "//preface/clause | //acknowledgements")), ) end |
#clause_order_back(_docxml) ⇒ Object
153 154 155 156 157 158 159 160 |
# File 'lib/isodoc/un/xref.rb', line 153 def clause_order_back(_docxml) [ { path: "//bibliography/references | //bibliography/clause", multi: true }, { path: "//indexsect", multi: true }, { path: "//colophon/*", multi: true }, ] end |
#clause_order_main(_docxml) ⇒ Object
6 7 8 |
# File 'lib/isodoc/un/xref.rb', line 6 def clause_order_main(_docxml) [{ path: "//sections/clause | //sections/terms | //sections/definitions", multi: true }] end |
#hierarchical_admonition_names(clause, num) ⇒ Object
172 173 174 175 176 177 178 179 180 |
# File 'lib/isodoc/un/xref.rb', line 172 def hierarchical_admonition_names(clause, num) i = 0 clause.xpath(ns(".//admonition")).noblank.each do |t| i += 1 unless t["unnumbered"] == "true" @anchors[t["id"]] = anchor_struct("#{num}.#{i}", nil, @labels["admonition"], "box", t["unnumbered"]) end end |
#hierarchical_asset_names(clause, num) ⇒ Object
187 188 189 190 |
# File 'lib/isodoc/un/xref.rb', line 187 def hierarchical_asset_names(clause, num) super hierarchical_admonition_names(clause, num) end |
#label_annex_leaf_section(clause, num, lvl) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/isodoc/un/xref.rb', line 58 def label_annex_leaf_section(clause, num, lvl) @paranumber += 1 @anchors[clause["id"]] = { label: @paranumber.to_s, elem: @labels["paragraph"], xref: l10n("#{@labels['paragraph']} #{num}.#{@paranumber}"), level: lvl, type: "paragraph" } end |
#label_leaf_section(clause, lvl) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/isodoc/un/xref.rb', line 49 def label_leaf_section(clause, lvl) @paranumber.nil? and @paranumber = 0 @paranumber += 1 @anchors[clause["id"]] = { label: @paranumber.to_s, elem: @labels["paragraph"], xref: l10n("#{@labels['paragraph']} #{@paranumber}"), level: lvl, type: "paragraph" } end |
#leaf_section?(clause) ⇒ Boolean
43 44 45 46 47 |
# File 'lib/isodoc/un/xref.rb', line 43 def leaf_section?(clause) !clause.at(ns(NONTERMINAL)) && !%w(definitions annex terms).include?(clause.name) && clause.at(ns("./p | ./bibitem")) end |
#levelnumber(num, lvl) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/isodoc/un/xref.rb', line 24 def levelnumber(num, lvl) case lvl % 3 when 1 then RomanNumerals.to_roman(num.to_i) when 2 then ("A".ord + num.to_i - 1).chr when 0 then num.to_s end end |
#main_anchor_names(xml) ⇒ Object
19 20 21 22 |
# File 'lib/isodoc/un/xref.rb', line 19 def main_anchor_names(xml) @paranumber = 0 super end |
#section_names(clause, num, lvl) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/isodoc/un/xref.rb', line 66 def section_names(clause, num, lvl) clause.nil? and return num leaf_section?(clause) and label_leaf_section(clause, lvl) and return lbl = levelnumber(num.increment(clause).print, 1) @anchors[clause["id"]] = { label: lbl, level: lvl, type: "clause", elem: @labels["clause"], xref: l10n("#{@labels['clause']} #{lbl}") } i = 1 clause.xpath(ns(NONTERMINAL)).each do |c| section_names1(c, "#{lbl}.#{levelnumber(i, lvl + 1)}", lvl + 1) i += 1 if !leaf_section?(c) && c["unnumbered"] != "true" end num end |
#section_names1(clause, num, level) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/isodoc/un/xref.rb', line 81 def section_names1(clause, num, level) leaf_section?(clause) and label_leaf_section(clause, level) and return /\.(?<leafnum>[^.]+$)/ =~ num clause["unnumbered"] == "true" or @anchors[clause["id"]] = { label: leafnum, level: level, type: "clause", elem: @labels["clause"], xref: l10n("#{@labels['clause']} #{num}") } i = 1 clause.xpath(ns(NONTERMINAL)).each do |c| section_names1(c, "#{num}.#{levelnumber(i, level + 1)}", level + 1) i += 1 if !leaf_section?(c) && c["unnumbered"] != "true" end end |
#sequential_admonition_names(clause, container: false) ⇒ Object
162 163 164 165 166 167 168 169 170 |
# File 'lib/isodoc/un/xref.rb', line 162 def sequential_admonition_names(clause, container: false) i = 0 clause.xpath(ns(".//admonition")).noblank.each do |t| i += 1 unless t["unnumbered"] == "true" @anchors[t["id"]] = anchor_struct(i.to_s, container ? t : nil, @labels["admonition"], "box", t["unnumbered"]) end end |
#sequential_asset_names(clause, container: false) ⇒ Object
182 183 184 185 |
# File 'lib/isodoc/un/xref.rb', line 182 def sequential_asset_names(clause, container: false) super sequential_admonition_names(clause, container: container) end |