Class: IsoDoc::Iso::Xref

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#anchors ⇒ Object

Returns the value of attribute anchors.



9
10
11
# File 'lib/isodoc/iso/xref.rb', line 9

def anchors
  @anchors
end

#anchors_previous ⇒ Object

Returns the value of attribute anchors_previous.



9
10
11
# File 'lib/isodoc/iso/xref.rb', line 9

def anchors_previous
  @anchors_previous
end

Instance Method Details

#annex_name_anchors1(clause, num, level) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/isodoc/iso/xref_section.rb', line 56

def annex_name_anchors1(clause, num, level)
  level == 1 and return annex_name_anchors(clause, num, level)
  ret = { label: num, level: level, subtype: "annex" }
  ret2 = if level == 2
           xref = labelled_autonum(@labels["clause"], num)
           { xref:, # l10n("#{@labels['clause']} #{num}"),
             elem: @labels["clause"] }
         else
           { xref: semx(clause, num) }
         end
  @anchors[clause["id"]] = ret.merge(ret2)
end

#annex_namesx(clause, num) ⇒ Object

KILL



17
18
19
20
# File 'lib/isodoc/iso/xref_section.rb', line 17

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

#appendix_names1x(clause, parentnum, num, level, container) ⇒ Object

KILL



70
71
72
73
74
75
76
77
78
# File 'lib/isodoc/iso/xref_section.rb', line 70

def appendix_names1x(clause, parentnum, num, level, container)
  num = clause_number_semx(parentnum, clause, num)
  @anchors[clause["id"]] = { label: num, xref: num, level: level,
                             container: container }
  i = clause_counter(0)
  clause.xpath(ns("./clause | ./references")).each do |c|
    appendix_names1(c, num, i.increment(c).print, level + 1, container)
  end
end

#appendix_namesx(clause, _num) ⇒ Object

KILL



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/isodoc/iso/xref_section.rb', line 23

def appendix_namesx(clause, _num)
  i = clause_counter(0)
  clause.xpath(ns("./appendix")).each do |c|
    i.increment(c)
    num = semx(c, i.print)
    lbl = labelled_autonum(@labels["appendix"], num)
    @anchors[c["id"]] =
      anchor_struct(i.print, c, @labels["appendix"],
                    "clause").merge(level: 2, subtype: "annex",
                                    container: clause["id"])
    j = clause_counter(0)
    c.xpath(ns("./clause | ./references")).each do |c1|
      appendix_names1(c1, lbl, j.increment(c1).print, 3, clause["id"])
    end
  end
end

#asset_anchor_names(doc) ⇒ Object



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

def asset_anchor_names(doc)
  super
  @parse_settings.empty? or return
  sequential_asset_names(doc.xpath(ns("//preface/*")))
end

#bookmark_anchor_names(xml) ⇒ Object



221
222
223
224
225
226
227
228
229
230
# File 'lib/isodoc/iso/xref.rb', line 221

def bookmark_anchor_names(xml)
  xml.xpath(ns(".//bookmark")).noblank.each do |n|
    @anchors.dig(n["id"], :has_table_prefix) and next
    _parent, id = id_ancestor(n)
    # container = bookmark_container(parent)
    @anchors[n["id"]] = { type: "bookmark", label: nil, value: nil,
                          xref: @anchors.dig(id, :xref) || "???",
                          container: @anchors.dig(id, :container) }
  end
end

#clause_order_back(docxml) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/isodoc/iso/xref.rb', line 24

def clause_order_back(docxml)
  if @klass.amd?(docxml)
    [{ path: @klass.norm_ref_xpath },
     { path: @klass.bibliography_xpath },
     { path: "//indexsect", multi: true },
     { path: "//colophon/*", multi: true }]
  else super
  end
end

#clause_order_main(docxml) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/isodoc/iso/xref.rb', line 11

def clause_order_main(docxml)
  if @klass.amd?(docxml)
    [{ path: "//sections/clause", multi: true }]
  else
    [{ path: "//sections/clause[@type = 'scope']" },
     { path: @klass.norm_ref_xpath },
     { path:
       "#{@klass.middle_clause(docxml)} | //sections/terms | " \
       "//sections/clause[descendant::terms or descendant::definitions] | " \
       "//sections/definitions | //sections/clause[@type = 'section']", multi: true }]
  end
end

#fig_subfig_label(label, sublabel) ⇒ Object



74
75
76
# File 'lib/isodoc/iso/xref.rb', line 74

def fig_subfig_label(label, sublabel)
  "#{label} #{sublabel}"
end

#figure_anchor(elem, sublabel, label, klass, container: false) ⇒ Object



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

def figure_anchor(elem, sublabel, label, klass, container: false)
  if sublabel
    subfigure_anchor(elem, sublabel, label, klass, container: container)
  else
    @anchors[elem["id"]] = anchor_struct(
      label, elem, @labels[klass] || klass.capitalize, klass,
      { unnumb: elem["unnumbered"], container: }
    )
  end
end

#hierarchical_figure_class_names(clause, num) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/isodoc/iso/xref.rb', line 138

def hierarchical_figure_class_names(clause, num)
  c = {}
  j = 0
  clause.xpath(ns(".//figure[@class][not(@class = 'pseudocode')]"))
    .noblank.each do |t|
    c[t["class"]] ||= IsoDoc::XrefGen::Counter.new
    j = subfigure_increment(j, c[t["class"]], t)
    #label = "#{num}#{hier_separator}#{c.print}"
    sublabel = j.zero? ? nil : "#{(j + 96).chr})"
    figure_anchor(t, sublabel, hiersemx(clause, num, c[t["class"]], t), t["class"])
  end
end

#hierarchical_figure_names(clause, num) ⇒ Object



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

def hierarchical_figure_names(clause, num)
  c = IsoDoc::XrefGen::Counter.new
  j = 0
  clause.xpath(ns(FIGURE_NO_CLASS)).noblank.each do |t|
    j = subfigure_increment(j, c, t)
    #label = "#{num}#{hier_separator}#{c.print}"
    sublabel = subfigure_label(j)
    figure_anchor(t, sublabel, hiersemx(clause, num, c, t), "figure")
  end
  hierarchical_figure_class_names(clause, num)
end

#hierarchical_formula_names(clause, num) ⇒ Object



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

def hierarchical_formula_names(clause, num)
  c = IsoDoc::XrefGen::Counter.new
  clause.xpath(ns(".//formula")).noblank.each do |t|
    @anchors[t["id"]] = anchor_struct(
      #"#{num}#{hier_separator}#{c.increment(t).print}", t,
      hiersemx(clause, num, c.increment(t), t), t,
      t["inequality"] ? @labels["inequality"] : @labels["formula"],
      "formula", { unnumb: t["unnumbered"], container: true }
    )
  end
end

#hierarchical_table_names(clause, _num) ⇒ Object



232
233
234
235
# File 'lib/isodoc/iso/xref.rb', line 232

def hierarchical_table_names(clause, _num)
  super
  modspec_table_xrefs(clause) if @anchors_previous
end

#hierfigsep ⇒ Object



99
100
101
# File 'lib/isodoc/iso/xref.rb', line 99

def hierfigsep
  " "
end

#initial_anchor_names(doc) ⇒ Object



34
35
36
37
38
39
# File 'lib/isodoc/iso/xref.rb', line 34

def initial_anchor_names(doc)
  super
  if @parse_settings.empty? || @parse_settings[:clauses]
    introduction_names(doc.at(ns("//introduction")))
  end
end

#introduction_names(clause) ⇒ Object

we can reference 0-number clauses in introduction



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

def introduction_names(clause)
  clause.nil? and return
  clause.at(ns("./clause")) and
    @anchors[clause["id"]] = { label: nil, level: 1, type: "clause",
                               xref: clause.at(ns("./title"))&.text }
  i = clause_counter(0)
  clause.xpath(ns("./clause")).each do |c|
    section_names1(c, semx(clause, "0"), i.increment(c).print, 2)
  end
end

#list_anchor_names(sections) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/isodoc/iso/xref.rb', line 157

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.noblank.each do |n|
      n["id"] ||= "_#{UUIDTools::UUID.random_create}"
      @anchors[n["id"]] = anchor_struct(increment_label(notes, n, c), n,
                                        @labels["list"], "list",
                                        { unnumb: false, container: true })
      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, container: false) ⇒ Object



199
200
201
202
203
204
# File 'lib/isodoc/iso/xref.rb', line 199

def modspec_table_components_xrefs(table, table_label, container: false)
  table.xpath(ns(".//tr[@id] | .//td[@id] | .//bookmark[@id]")).each do |tr|
    xref_to_modspec(tr["id"], table_label) or next
    container or @anchors[tr["id"]].delete(:container)
  end
end

#modspec_table_xrefs(clause, container: false) ⇒ Object



191
192
193
194
195
196
197
# File 'lib/isodoc/iso/xref.rb', line 191

def modspec_table_xrefs(clause, container: false)
  clause.xpath(ns(".//table[@class = 'modspec']")).noblank.each do |t|
    n = @anchors[t["id"]][:xref]
    xref_to_modspec(t["id"], n) or next
    modspec_table_components_xrefs(t, n, container: container)
  end
end

#note_anchor_names1(notes, counter) ⇒ Object



242
243
244
245
246
247
248
249
250
# File 'lib/isodoc/iso/xref.rb', line 242

def note_anchor_names1(notes, counter)
  countable = notes.reject { |n| uncountable_note?(n) }
  countable.each do |n|
    @anchors[n["id"]] =
      anchor_struct(increment_label(countable, n, counter), n,
                    @labels["note_xref"], "note",
                    { unnum: false, container: true })
  end
end

#reference_names(ref) ⇒ Object



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

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

#section_name_anchors(clause, num, level) ⇒ Object

subclauses are not prefixed with "Clause" retaining subtype for the semantics



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/isodoc/iso/xref_section.rb', line 42

def section_name_anchors(clause, num, level)
  if clause["type"] == "section"
    xref = labelled_autonum(@labels["section"], num)
    label = labelled_autonum(@labels["section"], num)
    @anchors[clause["id"]] =
      { label:, xref:, elem: @labels["section"],
        title: clause_title(clause), level: level, type: "clause" }
  elsif level > 1
    #num = semx(clause, num)
    @anchors[clause["id"]] =
      { label: num, level: level, xref: num, subtype: "clause" }
  else super end
end

#sequential_figure_class_names(clause, container: false) ⇒ Object



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

def sequential_figure_class_names(clause, container: false)
  c = {}
  j = 0
  clause.xpath(ns(".//figure[@class][not(@class = 'pseudocode')]"))
    .each do |t|
    c[t["class"]] ||= IsoDoc::XrefGen::Counter.new
    j = subfigure_increment(j, c[t["class"]], t)
    sublabel = j.zero? ? nil : "#{(j + 96).chr})"
    figure_anchor(t, sublabel, c.print, t["class"], container: container)
  end
end

#sequential_figure_names(clause, container: false) ⇒ Object



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

def sequential_figure_names(clause, container: false)
  j = 0
  clause.xpath(ns(FIGURE_NO_CLASS)).noblank
    .each_with_object(IsoDoc::XrefGen::Counter.new) do |t, c|
    j = subfigure_increment(j, c, t)
    sublabel = subfigure_label(j)
    figure_anchor(t, sublabel, c.print, "figure", container: container)
  end
  sequential_figure_class_names(clause, container: container)
end

#sequential_table_names(clause, container: false) ⇒ Object



186
187
188
189
# File 'lib/isodoc/iso/xref.rb', line 186

def sequential_table_names(clause, container: false)
  super
  modspec_table_xrefs(clause, container: container) if @anchors_previous
end

#single_ol_for_xrefs?(lists) ⇒ Boolean

all li in the ol in lists are consecutively numbered through @start

Returns:

  • (Boolean)


175
176
177
178
179
180
181
182
183
184
# File 'lib/isodoc/iso/xref.rb', line 175

def single_ol_for_xrefs?(lists)
  lists.size == 1 and return true
  start = 0
  lists.each_with_index do |l, i|
    i.zero? and next
    start += lists[i - 1].xpath(ns("./li")).size
    return false unless l["start"]&.to_i == start + 1
  end
  true
end

#subfigure_anchor(elem, sublabel, label, klass, container: false) ⇒ Object



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

def subfigure_anchor(elem, sublabel, label, klass, container: false)
  figlabel = fig_subfig_label(label, sublabel)
  @anchors[elem["id"]] = anchor_struct(
    figlabel, elem, @labels[klass] || klass.capitalize, klass,
    { unnumb: elem["unnumbered"] }
  )
  if elem["unnumbered"] != "true"
    # Dropping the parent figure label is specific to ISO
    @anchors[elem["id"]][:label] = sublabel
    @anchors[elem["id"]][:xref] = @anchors[elem.parent["id"]][:xref] +
      " " + semx(elem, sublabel) + delim_wrap(subfigure_delim)
              x = @anchors[elem.parent["id"]][:container] and
    @anchors[elem["id"]][:container] = x
  end
end

#subfigure_delim ⇒ Object



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

def subfigure_delim
  ")"
end

#subfigure_label(subfignum) ⇒ Object



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

def subfigure_label(subfignum)
  subfignum.zero? and return
  (subfignum + 96).chr
end

#uncountable_note?(note) ⇒ Boolean

Returns:

  • (Boolean)


237
238
239
240
# File 'lib/isodoc/iso/xref.rb', line 237

def uncountable_note?(note)
  @anchors[note["id"]] || blank?(note["id"]) || note["type"] == "units" ||
    note["type"] == "requirement"
end

#xref_to_modspec(id, table_label) ⇒ Object



206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/isodoc/iso/xref.rb', line 206

def xref_to_modspec(id, table_label)
  #(@anchors[id] && !@anchors[id][:has_modspec]) or return
  (@anchors[id] && !@anchors[id][:has_table_prefix]) or return
  @anchors[id][:has_table_prefix] = true
  x = @anchors_previous[id][:xref_bare] || @anchors_previous[id][:xref]
  # @anchors[id][:xref] = l10n("#{table_label}<span class='fmt-comma'>,</span> #{x}")

  @anchors[id][:xref] = l10n(@klass.connectives_spans(@i18n.nested_xref
    .sub("%1", table_label).sub("%2", x)))

  @anchors[id][:modspec] = @anchors_previous[id][:modspec]
  @anchors[id][:subtype] = "modspec" # prevents citetbl style from beign applied
  true
end