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



42
43
44
45
# File 'lib/isodoc/iso/xref.rb', line 42

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

#annex_names1(clause, num, level) ⇒ Object



77
78
79
80
81
82
83
84
# File 'lib/isodoc/iso/xref.rb', line 77

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



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/isodoc/iso/xref.rb', line 47

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



86
87
88
89
90
91
92
93
94
# File 'lib/isodoc/iso/xref.rb', line 86

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



150
151
152
153
# File 'lib/isodoc/iso/xref.rb', line 150

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

#figure_anchor(t, sublabel, label) ⇒ Object



108
109
110
111
112
113
114
115
# File 'lib/isodoc/iso/xref.rb', line 108

def figure_anchor(t, sublabel, label)
  @anchors[t["id"]] = anchor_struct(
    (sublabel ? "#{label} #{sublabel}" : label),
    nil, @labels["figure"], "figure", t["unnumbered"]
  )
  sublabel && t["unnumbered"] != "true" and
    @anchors[t["id"]][:label] = sublabel
end

#hierarchical_figure_names(clause, num) ⇒ Object



130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/isodoc/iso/xref.rb', line 130

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



96
97
98
99
100
101
102
103
104
105
106
# File 'lib/isodoc/iso/xref.rb', line 96

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
    super
  end
  introduction_names(doc.at(ns("//introduction")))
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



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

def introduction_names(clause)
  return if clause.nil?

  clause.at(ns("./clause")) and @anchors[clause["id"]] =
    { label: "0", level: 1, xref: clause.at(ns("./title"))&.text, type: "clause" }
  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



144
145
146
147
148
# File 'lib/isodoc/iso/xref.rb', line 144

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

#section_names1(clause, num, level) ⇒ Object



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

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



117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/isodoc/iso/xref.rb', line 117

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