Class: IsoDoc::Iso::Xref
- Inherits:
-
Xref
- Object
- Xref
- IsoDoc::Iso::Xref
- Defined in:
- lib/isodoc/iso/xref.rb
Instance Attribute Summary collapse
-
#anchors ⇒ Object
Returns the value of attribute anchors.
-
#anchors_previous ⇒ Object
Returns the value of attribute anchors_previous.
Instance Method Summary collapse
- #annex_name_lbl(clause, num) ⇒ Object
- #annex_names(clause, num) ⇒ Object
- #annex_names1(clause, num, level) ⇒ Object
- #appendix_names(clause, _num) ⇒ Object
- #appendix_names1(clause, num, level, container) ⇒ Object
- #back_anchor_names(docxml) ⇒ Object
- #figure_anchor(elem, sublabel, label) ⇒ Object
- #hierarchical_figure_names(clause, num) ⇒ Object
- #hierarchical_formula_names(clause, num) ⇒ Object
- #hierarchical_table_names(clause, _num) ⇒ Object
- #initial_anchor_names(doc) ⇒ Object
- #initial_anchor_names1(doc) ⇒ Object
- #initial_anchor_names_amd(doc) ⇒ Object
-
#introduction_names(clause) ⇒ Object
we can reference 0-number clauses in introduction.
- #list_anchor_names(sections) ⇒ Object
- #modspec_table_components_xrefs(table, table_label) ⇒ Object
- #modspec_table_xrefs(clause) ⇒ Object
- #reference_names(ref) ⇒ Object
-
#section_names1(clause, num, level) ⇒ Object
subclauses are not prefixed with “Clause” retaining subtype for the semantics.
- #sequential_figure_names(clause) ⇒ Object
- #sequential_table_names(clause) ⇒ Object
-
#single_ol_for_xrefs?(lists) ⇒ Boolean
all li in the ol in lists are consecutively numbered through @start.
Instance Attribute Details
#anchors ⇒ Object
Returns the value of attribute anchors.
7 8 9 |
# File 'lib/isodoc/iso/xref.rb', line 7 def anchors @anchors end |
#anchors_previous ⇒ Object
Returns the value of attribute anchors_previous.
7 8 9 |
# File 'lib/isodoc/iso/xref.rb', line 7 def anchors_previous @anchors_previous end |
Instance Method Details
#annex_name_lbl(clause, num) ⇒ Object
188 189 190 |
# File 'lib/isodoc/iso/xref.rb', line 188 def annex_name_lbl(clause, num) super.sub(%r{<br/>(.*)$}, "<br/><span class='obligation'>\\1</span>") end |
#annex_names(clause, num) ⇒ Object
71 72 73 74 |
# File 'lib/isodoc/iso/xref.rb', line 71 def annex_names(clause, num) appendix_names(clause, num) super end |
#annex_names1(clause, num, level) ⇒ Object
107 108 109 110 111 112 113 114 115 |
# File 'lib/isodoc/iso/xref.rb', line 107 def annex_names1(clause, num, level) @anchors[clause["id"]] = { label: num, xref: num, level: level, subtype: "annex" } i = Counter.new clause.xpath(ns("./clause | ./references")).each do |c| i.increment(c) annex_names1(c, "#{num}.#{i.print}", level + 1) end end |
#appendix_names(clause, _num) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/isodoc/iso/xref.rb', line 76 def appendix_names(clause, _num) i = Counter.new clause.xpath(ns("./appendix")).each do |c| i.increment(c) @anchors[c["id"]] = anchor_struct(i.print, nil, @labels["appendix"], "clause").merge(level: 2, subtype: "annex", container: clause["id"]) j = Counter.new c.xpath(ns("./clause | ./references")).each do |c1| j.increment(c1) lbl = "#{@labels['appendix']} #{i.print}.#{j.print}" appendix_names1(c1, l10n(lbl), 3, clause["id"]) end end end |
#appendix_names1(clause, num, level, container) ⇒ Object
117 118 119 120 121 122 123 124 125 |
# File 'lib/isodoc/iso/xref.rb', line 117 def appendix_names1(clause, num, level, container) @anchors[clause["id"]] = { label: num, xref: num, level: level, container: container } i = Counter.new clause.xpath(ns("./clause | ./references")).each do |c| i.increment(c) appendix_names1(c, "#{num}.#{i.print}", level + 1, container) end end |
#back_anchor_names(docxml) ⇒ Object
181 182 183 184 185 186 |
# File 'lib/isodoc/iso/xref.rb', line 181 def back_anchor_names(docxml) super if @parse_settings.empty? || @parse_settings[:clauses] docxml.xpath(ns("//indexsect")).each { |b| preface_names(b) } end end |
#figure_anchor(elem, sublabel, label) ⇒ Object
140 141 142 143 144 145 146 147 |
# File 'lib/isodoc/iso/xref.rb', line 140 def figure_anchor(elem, sublabel, label) @anchors[elem["id"]] = anchor_struct( (sublabel ? "#{label} #{sublabel}" : label), nil, @labels["figure"], "figure", elem["unnumbered"] ) sublabel && elem["unnumbered"] != "true" and @anchors[elem["id"]][:label] = sublabel end |
#hierarchical_figure_names(clause, num) ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/isodoc/iso/xref.rb', line 161 def hierarchical_figure_names(clause, num) c = IsoDoc::XrefGen::Counter.new j = 0 clause.xpath(ns(".//figure | .//sourcecode[not(ancestor::example)]")) .each do |t| j = subfigure_increment(j, c, t) label = "#{num}#{hiersep}#{c.print}" sublabel = j.zero? ? nil : "#{(j + 96).chr})" next if blank?(t["id"]) figure_anchor(t, sublabel, label) end end |
#hierarchical_formula_names(clause, num) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/isodoc/iso/xref.rb', line 127 def hierarchical_formula_names(clause, num) c = IsoDoc::XrefGen::Counter.new clause.xpath(ns(".//formula")).each do |t| next if blank?(t["id"]) @anchors[t["id"]] = anchor_struct( "#{num}#{hiersep}#{c.increment(t).print}", t, t["inequality"] ? @labels["inequality"] : @labels["formula"], "formula", t["unnumbered"] ) end end |
#hierarchical_table_names(clause, _num) ⇒ Object
247 248 249 250 |
# File 'lib/isodoc/iso/xref.rb', line 247 def hierarchical_table_names(clause, _num) super modspec_table_xrefs(clause) if @anchors_previous end |
#initial_anchor_names(doc) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/isodoc/iso/xref.rb', line 9 def initial_anchor_names(doc) if @klass.amd(doc) then initial_anchor_names_amd(doc) else initial_anchor_names1(doc) end if @parse_settings.empty? || @parse_settings[:clauses] introduction_names(doc.at(ns("//introduction"))) end end |
#initial_anchor_names1(doc) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/isodoc/iso/xref.rb', line 35 def initial_anchor_names1(doc) if @parse_settings.empty? || @parse_settings[:clauses] doc.xpath(ns("//preface/*")).each do |c| c.element? and preface_names(c) end # potentially overridden in middle_section_asset_names() sequential_asset_names(doc.xpath(ns("//preface/*"))) n = Counter.new n = section_names(doc.at(ns("//clause[@type = 'scope']")), n, 1) n = section_names(doc.at(ns(@klass.norm_ref_xpath)), n, 1) doc.xpath(ns("//sections/clause[not(@type = 'scope')] | "\ "//sections/terms | //sections/definitions")).each do |c| n = section_names(c, n, 1) end end if @parse_settings.empty? middle_section_asset_names(doc) termnote_anchor_names(doc) termexample_anchor_names(doc) end end |
#initial_anchor_names_amd(doc) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/isodoc/iso/xref.rb', line 18 def initial_anchor_names_amd(doc) if @parse_settings.empty? || @parse_settings[:clauses] doc.xpath(ns("//preface/*")).each do |c| c.element? and preface_names(c) end doc.xpath(ns("//sections/clause")).each do |c| c.element? and preface_names(c) end end if @parse_settings.empty? sequential_asset_names(doc.xpath(ns("//preface/*"))) middle_section_asset_names(doc) termnote_anchor_names(doc) termexample_anchor_names(doc) end end |
#introduction_names(clause) ⇒ Object
we can reference 0-number clauses in introduction
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/isodoc/iso/xref.rb', line 58 def introduction_names(clause) return if clause.nil? clause.at(ns("./clause")) and @anchors[clause["id"]] = { label: "0", level: 1, type: "clause", xref: clause.at(ns("./title"))&.text } i = Counter.new clause.xpath(ns("./clause")).each do |c| i.increment(c) section_names1(c, "0.#{i.print}", 2) end end |
#list_anchor_names(sections) ⇒ Object
192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/isodoc/iso/xref.rb', line 192 def list_anchor_names(sections) sections.each do |s| notes = s.xpath(ns(".//ol")) - s.xpath(ns(".//clause//ol")) - s.xpath(ns(".//appendix//ol")) - s.xpath(ns(".//ol//ol")) c = Counter.new notes.reject { |n| blank?(n["id"]) }.each do |n| @anchors[n["id"]] = anchor_struct(increment_label(notes, n, c), n, @labels["list"], "list", false) list_item_anchor_names(n, @anchors[n["id"]], 1, "", !single_ol_for_xrefs?(notes)) end list_anchor_names(s.xpath(ns(CHILD_SECTIONS))) end end |
#modspec_table_components_xrefs(table, table_label) ⇒ Object
237 238 239 240 241 242 243 244 245 |
# File 'lib/isodoc/iso/xref.rb', line 237 def modspec_table_components_xrefs(table, table_label) table.xpath(ns(".//tr[@id]")).each do |tr| (@anchors[tr["id"]] && !@anchors[tr["id"]][:modspec]) or next @anchors[tr["id"]][:modspec] = true @anchors[tr["id"]][:xref] = l10n("#{table_label}, #{@anchors_previous[tr['id']][:xref]}") @anchors[tr["id"]].delete(:container) end end |
#modspec_table_xrefs(clause) ⇒ Object
226 227 228 229 230 231 232 233 234 235 |
# File 'lib/isodoc/iso/xref.rb', line 226 def modspec_table_xrefs(clause) clause.xpath(ns(".//table[@class = 'modspec']")).noblank.each do |t| (@anchors[t["id"]] && !@anchors[t["id"]][:modspec]) or next n = @anchors[t["id"]][:xref] @anchors[t["id"]][:modspec] = true @anchors[t["id"]][:xref] = l10n("#{n}, #{@anchors_previous[t['id']][:xref_bare]}") modspec_table_components_xrefs(t, n) end end |
#reference_names(ref) ⇒ Object
175 176 177 178 179 |
# File 'lib/isodoc/iso/xref.rb', line 175 def reference_names(ref) super @anchors[ref["id"]] = { xref: @anchors[ref["id"]][:xref] .sub(/ \(All Parts\)/i, "") } end |
#section_names1(clause, num, level) ⇒ Object
subclauses are not prefixed with “Clause” retaining subtype for the semantics
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/isodoc/iso/xref.rb', line 95 def section_names1(clause, num, level) @anchors[clause["id"]] = { label: num, level: level, xref: num, subtype: "clause" } i = Counter.new clause.xpath(ns("./clause | ./terms | ./term | ./definitions | "\ "./references")) .each do |c| i.increment(c) section_names1(c, "#{num}.#{i.print}", level + 1) end end |
#sequential_figure_names(clause) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/isodoc/iso/xref.rb', line 149 def sequential_figure_names(clause) j = 0 clause.xpath(ns(".//figure | .//sourcecode[not(ancestor::example)]")) .each_with_object(IsoDoc::XrefGen::Counter.new) do |t, c| j = subfigure_increment(j, c, t) sublabel = j.zero? ? nil : "#{(j + 96).chr})" next if blank?(t["id"]) figure_anchor(t, sublabel, c.print) end end |
#sequential_table_names(clause) ⇒ Object
221 222 223 224 |
# File 'lib/isodoc/iso/xref.rb', line 221 def sequential_table_names(clause) super modspec_table_xrefs(clause) if @anchors_previous end |
#single_ol_for_xrefs?(lists) ⇒ Boolean
all li in the ol in lists are consecutively numbered through @start
208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/isodoc/iso/xref.rb', line 208 def single_ol_for_xrefs?(lists) return true if lists.size == 1 start = 0 lists.each_with_index do |l, i| next if i.zero? start += lists[i - 1].xpath(ns("./li")).size return false unless l["start"]&.to_i == start + 1 end true end |