Class: IsoDoc::Iso::Xref

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

Instance Method Summary collapse

Instance Method Details

#annex_names(clause, num) ⇒ Object



59
60
61
62
# File 'lib/isodoc/iso/xref.rb', line 59

def annex_names(clause, num)
  appendix_names(clause, num)
  super
end

#annex_names1(clause, num, level) ⇒ Object



94
95
96
97
98
99
100
101
# File 'lib/isodoc/iso/xref.rb', line 94

def annex_names1(clause, num, level)
  @anchors[clause["id"]] = { label: num, xref: num, level: level }
  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



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

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")
    @anchors[c["id"]][:level] = 2
    @anchors[c["id"]][: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



103
104
105
106
107
108
109
110
111
# File 'lib/isodoc/iso/xref.rb', line 103

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



168
169
170
171
# File 'lib/isodoc/iso/xref.rb', line 168

def back_anchor_names(docxml)
  super
  docxml.xpath(ns("//indexsect")).each { |b| preface_names(b) }
end

#figure_anchor(elem, sublabel, label) ⇒ Object



126
127
128
129
130
131
132
133
# File 'lib/isodoc/iso/xref.rb', line 126

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



148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/isodoc/iso/xref.rb', line 148

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 t["id"].nil? || t["id"].empty?

    figure_anchor(t, sublabel, label)
  end
end

#hierarchical_formula_names(clause, num) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/isodoc/iso/xref.rb', line 113

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}#{hiersep}#{c.increment(t).print}", t,
      t["inequality"] ? @labels["inequality"] : @labels["formula"],
      "formula", t["unnumbered"]
    )
  end
end

#initial_anchor_names(doc) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/isodoc/iso/xref.rb', line 7

def initial_anchor_names(doc)
  if @klass.amd(doc)
    initial_anchor_names_amd(doc)
  else
    initial_anchor_names1(doc)
  end
  introduction_names(doc.at(ns("//introduction")))
end

#initial_anchor_names1(doc) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/isodoc/iso/xref.rb', line 29

def initial_anchor_names1(doc)
  doc.xpath(ns("//preface/*")).each { |c| c.element? and preface_names(c) }
  # 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
  middle_section_asset_names(doc)
  termnote_anchor_names(doc)
  termexample_anchor_names(doc)
end

#initial_anchor_names_amd(doc) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/isodoc/iso/xref.rb', line 16

def initial_anchor_names_amd(doc)
  doc.xpath(ns("//preface/*")).each do |c|
    c.element? and preface_names(c)
  end
  sequential_asset_names(doc.xpath(ns("//preface/*")))
  doc.xpath(ns("//sections/clause")).each do |c|
    c.element? and preface_names(c)
  end
  middle_section_asset_names(doc)
  termnote_anchor_names(doc)
  termexample_anchor_names(doc)
end

#introduction_names(clause) ⇒ Object

we can reference 0-number clauses in introduction



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/isodoc/iso/xref.rb', line 46

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

#reference_names(ref) ⇒ Object



162
163
164
165
166
# File 'lib/isodoc/iso/xref.rb', line 162

def reference_names(ref)
  super
  @anchors[ref["id"]] = { xref: @anchors[ref["id"]][:xref]
    .sub(/ \(All Parts\)/i, "") }
end

#section_names1(clause, num, level) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/isodoc/iso/xref.rb', line 81

def section_names1(clause, num, level)
  @anchors[clause["id"]] =
    { label: num, level: level, xref: num }
  # subclauses are not prefixed with "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



135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/isodoc/iso/xref.rb', line 135

def sequential_figure_names(clause)
  c = IsoDoc::XrefGen::Counter.new
  j = 0
  clause.xpath(ns(".//figure | .//sourcecode[not(ancestor::example)]"))
    .each do |t|
    j = subfigure_increment(j, c, t)
    sublabel = j.zero? ? nil : "#{(j + 96).chr})"
    next if t["id"].nil? || t["id"].empty?

    figure_anchor(t, sublabel, c.print)
  end
end