Class: IsoDoc::Iho::Xref

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

Instance Method Summary collapse

Instance Method Details

#anchor_struct_value(lbl, elem) ⇒ Object



50
51
52
53
# File 'lib/isodoc/iho/xref.rb', line 50

def anchor_struct_value(lbl, elem)
  @annex_prefix and lbl = l10n("#{@annex_prefix} #{lbl}")
  super
end

#annex_anchor_names(docxml) ⇒ Object



80
81
82
83
84
85
86
87
88
89
# File 'lib/isodoc/iho/xref.rb', line 80

def annex_anchor_names(docxml)
  clause_order_annex(docxml).each_with_index do |a, i|
    n = i.zero? ? Counter.new("@", skip_i: true) : Counter.new
    docxml.xpath(ns(a[:path]))
      .each do |c|
      annex_names(c, n.increment(c).print)
      a[:multi] or break
    end
  end
end

#annex_asset_names(clause, num, lbl) ⇒ Object



44
45
46
47
48
# File 'lib/isodoc/iho/xref.rb', line 44

def annex_asset_names(clause, num, lbl)
  @annex_prefix = lbl
  hierarchical_asset_names(clause, num)
  @annex_prefix = nil
end

#annex_name_lbl(clause, num) ⇒ Object



17
18
19
20
# File 'lib/isodoc/iho/xref.rb', line 17

def annex_name_lbl(clause, num)
  lbl = annexlbl(clause["obligation"] == "informative")
  l10n("<strong>#{lbl} #{num}</strong>")
end

#annex_names(clause, num) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/isodoc/iho/xref.rb', line 22

def annex_names(clause, num)
  appendix_names(clause, num)
  lbl = annexlbl(clause["obligation"] == "informative")
  @anchors[clause["id"]] =
    { label: annex_name_lbl(clause, num), type: "clause", elem: lbl,
      xref: l10n("#{lbl} #{num}"), level: 1, value: num }
  annex_names_recurse(clause, num)
  annex_asset_names(clause, num, lbl)
end

#annex_names1(clause, num, level) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/isodoc/iho/xref.rb', line 91

def annex_names1(clause, num, level)
  lbl = annexlbl(clause.at("./ancestor::xmlns:annex/@obligation")
      .text == "informative")
  @anchors[clause["id"]] =
    { label: num, xref: l10n("#{lbl} #{num}"),
      level: level, type: "clause" }
  i = Counter.new(0, prefix: "#{num}.")
  clause.xpath(ns("./clause | ./references | ./terms | ./definitions"))
    .each do |c|
    annex_names1(c, i.increment(c).print, level + 1)
  end
end

#annex_names_recurse(clause, num) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/isodoc/iho/xref.rb', line 32

def annex_names_recurse(clause, num)
  @klass.single_term_clause?(clause) and
    return annex_names1(clause.at(ns("./references | ./terms | ./definitions")),
                        num.to_s, 1)
  i = Counter.new
  clause.xpath(ns("./clause | ./references | ./terms | ./definitions"))
    .each do |c|
    i.increment(c)
    annex_names1(c, "#{num}.#{i.print}", 2)
  end
end

#annexlbl(cond) ⇒ Object



13
14
15
# File 'lib/isodoc/iho/xref.rb', line 13

def annexlbl(cond)
  cond ? @labels["appendix"] : @labels["annex"]
end

#appendix_names(clause, _num) ⇒ Object



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

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"]
  end
end

#clause_order_annex(_docxml) ⇒ Object



75
76
77
78
# File 'lib/isodoc/iho/xref.rb', line 75

def clause_order_annex(_docxml)
  [{ path: "//annex[not(@obligation = 'informative')]", multi: true },
   { path: "//annex[@obligation = 'informative']", multi: true }]
end

#clause_order_main(docxml) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/isodoc/iho/xref.rb', line 55

def clause_order_main(docxml)
  if docxml.at(ns("//bibliography//references[@normative = 'true']")) ||
      docxml.at(ns("//sections/references[@normative = 'true']"))
    [
      { path: "//sections/clause[@type = 'scope']" },
      { path: "#{@klass.norm_ref_xpath} | //sections/references" },
      { path: "//sections/terms | //sections/definitions | " \
        "//sections/clause[not(@type = 'scope')]", multi: true },
    ]
  else
    [
      { path: "//sections/terms | //sections/definitions | " \
        "//sections/references | " \
        "//bibliography/references[@normative = 'true'] | " \
        "//bibliography/clause[.//references[@normative = 'true']] | " \
        "//sections/clause", multi: true },
    ]
  end
end

#hiersepObject



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

def hiersep
  "-"
end

#middle_section_asset_names(doc) ⇒ Object



131
132
133
134
135
# File 'lib/isodoc/iho/xref.rb', line 131

def middle_section_asset_names(doc)
  doc.xpath(ns(middle_sections)).each do |c|
    hierarchical_asset_names(c, @anchors[c["id"]][:label])
  end
end

#middle_sectionsObject



126
127
128
129
# File 'lib/isodoc/iho/xref.rb', line 126

def middle_sections
  "//sections/clause | #{@klass.norm_ref_xpath} | " \
    "//sections/terms | //sections/definitions | //sections/clause"
end

#preface_names(clause) ⇒ Object



137
138
139
140
# File 'lib/isodoc/iho/xref.rb', line 137

def preface_names(clause)
  super
  sequential_asset_names(clause, container: true)
end

#section_names1(clause, num, level) ⇒ Object



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

def section_names1(clause, num, level)
  @anchors[clause["id"]] =
    { label: num, level: level,
      xref: l10n("#{@labels['subclause']} #{num}"),
      type: "clause", elem: @labels["subclause"] }
  i = Counter.new(0, prefix: "#{num}.")
  clause.xpath(ns(SUBCLAUSES)).each do |c|
    section_names1(c, i.increment(c).print, level + 1)
  end
end