Class: IsoDoc::Ogc::Xref

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

Constant Summary collapse

FIRST_LVL_REQ =
IsoDoc::XrefGen::Blocks::FIRST_LVL_REQ
REQS =
%w(permission requirement recommendation).freeze

Instance Method Summary collapse

Constructor Details

#initialize(lang, script, klass, labels, options) ⇒ Xref

Returns a new instance of Xref.



7
8
9
10
# File 'lib/isodoc/ogc/xref.rb', line 7

def initialize(lang, script, klass, labels, options)
  @reqtlabels = {}
  super
end

Instance Method Details

#hierarchical_asset_names(clause, num) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/isodoc/ogc/xref.rb', line 103

def hierarchical_asset_names(clause, num)
  hierarchical_table_names(clause, num)
  hierarchical_figure_names(clause, num)
  hierarchical_formula_names(clause, num)
  req_class_paths.each do |k, v|
    REQS.each do |r|
      hierarchical_permission_names(clause, num, "#{r}[#{v}]",
                                    @labels["#{r}#{k}"])
    end
  end
  req_class_paths2.each do |k, v|
    hierarchical_permission_names(clause, num, "*[#{v}]", @labels[k])
  end
end

#hierarchical_permission_names(clause, num, klass, label) ⇒ Object



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

def hierarchical_permission_names(clause, num, klass, label)
  c = Counter.new
  clause.xpath(ns(".//#{klass}#{FIRST_LVL_REQ}")).each do |t|
    next if t["id"].nil? || t["id"].empty?

    lbl = "#{num}#{hiersep}#{c.increment(t).print}"
    @anchors[t["id"]] = anchor_struct(lbl, t, label, klass,
                                      t["unnumbered"])
    reqt_suffix_label(t)
    permission_parts(t, label, klass)
    sequential_permission_children(t, lbl)
  end
end

#initial_anchor_names(doc) ⇒ Object



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/isodoc/ogc/xref.rb', line 132

def initial_anchor_names(doc)
  if @parse_settings.empty? || @parse_settings[:clauses]
  preface_anchor_names(doc)
  n = Counter.new
  n = section_names(doc.at(ns("//clause[@type = 'scope']")), n, 1)
  n = section_names(doc.at(ns("//clause[@type = 'conformance']")), n, 1)
  n = section_names(doc.at(ns(@klass.norm_ref_xpath)), n, 1)
  n = section_names(
    doc.at(ns("//sections/terms | //sections/clause[descendant::terms]")),
    n, 1
  )
  n = section_names(doc.at(ns("//sections/definitions")), n, 1)
  clause_names(doc, n)
  end
  if @parse_settings.empty?
  middle_section_asset_names(doc)
  termnote_anchor_names(doc)
  termexample_anchor_names(doc)
  end
end

#middle_section_asset_names(doc) ⇒ Object



173
174
175
176
177
178
179
180
181
# File 'lib/isodoc/ogc/xref.rb', line 173

def middle_section_asset_names(doc)
  middle_sections =
    "//clause[@type = 'scope' or @type = 'conformance'] | //foreword | "\
    "//introduction | //preface/abstract | //submitters | "\
    "//acknowledgements | //preface/clause | "\
    " #{@klass.norm_ref_xpath} | //sections/terms | "\
    "//sections/definitions | //clause[parent::sections]"
  sequential_asset_names(doc.xpath(ns(middle_sections)))
end

#permission_parts(block, label, klass) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/isodoc/ogc/xref.rb', line 51

def permission_parts(block, label, klass)
  block.xpath(ns("./component[@class = 'part']"))
    .each_with_index do |c, i|
    next if c["id"].nil? || c["id"].empty?

    @anchors[c["id"]] = anchor_struct((i + "A".ord).chr.to_s, c, label,
                                      klass, c["unnumbered"])
  end
end

#preface_anchor_names(doc) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/isodoc/ogc/xref.rb', line 153

def preface_anchor_names(doc)
  @prefacenum = 0
  ["//preface/abstract", "//preface/clause[@type = 'executivesummary']",
   "//preface/clause[@type = 'keywords']",
   "//foreword", "//preface/clause[@type = 'security']",
   "//preface/clause[@type = 'submitting_orgs']", "//submitters",
   "//introduction"].each do |path|
    preface_names_numbered(doc.at(ns(path)))
  end
  doc.xpath(ns("//preface/clause[not(@type = 'keywords' or "\
               "@type = 'submitting_orgs' or @type = 'security' or "\
               "@type = 'executivesummary')]"))
    .each { |c| preface_names_numbered(c) }
  preface_names_numbered(doc.at(ns("//acknowledgements")))
  sequential_asset_names(
    doc.xpath(ns("//preface/abstract | //foreword | //introduction | "\
                 "//submitters | //acknowledgements | //preface/clause")),
  )
end

#preface_names_numbered(clause) ⇒ Object



183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/isodoc/ogc/xref.rb', line 183

def preface_names_numbered(clause)
  return if clause.nil?

  @prefacenum += 1
  pref = preface_number(@prefacenum, 1)
  @anchors[clause["id"]] =
    { label: pref,
      level: 1, xref: preface_clause_name(clause), type: "clause" }
  clause.xpath(ns(SUBCLAUSES)).each_with_index do |c, i|
    preface_names_numbered1(c, "#{pref}.#{preface_number(i + 1, 2)}", 2)
  end
end

#preface_names_numbered1(clause, num, level) ⇒ Object



196
197
198
199
200
201
202
203
204
# File 'lib/isodoc/ogc/xref.rb', line 196

def preface_names_numbered1(clause, num, level)
  @anchors[clause["id"]] =
    { label: num, level: level, xref: l10n("#{@labels['clause']} #{num}"),
      type: "clause", elem: @labels["clause"] }
  clause.xpath(ns(SUBCLAUSES)).each_with_index do |c, i|
    lbl = "#{num}.#{preface_number(i + 1, level + 1)}"
    preface_names_numbered1(c, lbl, level + 1)
  end
end

#preface_number(num, level) ⇒ Object



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

def preface_number(num, level)
  case level
  when 1 then RomanNumerals.to_roman(num).upcase
  when 2 then (64 + num).chr.to_s
  when 3 then num.to_s
  when 4 then (96 + num).chr.to_s
  when 5 then RomanNumerals.to_roman(num).downcase
  when 6 then "(#{num})"
  when 7 then "(#{(96 + num).chr})"
  when 8 then "(#{RomanNumerals.to_roman(num).downcase})"
  else num.to_s
  end
end

#reference_names(ref) ⇒ Object



220
221
222
223
224
225
# File 'lib/isodoc/ogc/xref.rb', line 220

def reference_names(ref)
  super
  return unless @klass.ogc_draft_ref?(ref)

  @anchors[ref["id"]] = { xref: "#{@anchors[ref['id']][:xref]} (draft)" }
end

#req_class_pathsObject



32
33
34
35
36
37
# File 'lib/isodoc/ogc/xref.rb', line 32

def req_class_paths
  { "class" => "@type = 'class'",
    "test" => "@type = 'verification'",
    "" => "not(@type = 'verification' or @type = 'class' or "\
          "@type = 'abstracttest' or @type = 'conformanceclass')" }
end

#req_class_paths2Object



39
40
41
42
# File 'lib/isodoc/ogc/xref.rb', line 39

def req_class_paths2
  { "abstracttest" => "@type = 'abstracttest'",
    "conformanceclass" => "@type = 'conformanceclass'" }
end

#reqt_suffix_label(reqt) ⇒ Object



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

def reqt_suffix_label(reqt)
  if l = reqt.at(ns("./label"))&.text
    @reqtlabels[l] = reqt["id"]
    @anchors[reqt["id"]][:xref] += ": <tt>#{l}</tt>"
  end
end

#reqtlabelsObject



12
13
14
# File 'lib/isodoc/ogc/xref.rb', line 12

def reqtlabels
  @reqtlabels
end

#sequential_asset_names(clause) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/isodoc/ogc/xref.rb', line 88

def sequential_asset_names(clause)
  sequential_table_names(clause)
  sequential_figure_names(clause)
  sequential_formula_names(clause)
  req_class_paths.each do |k, v|
    REQS.each do |r|
      sequential_permission_names(clause, "#{r}[#{v}]",
                                  @labels["#{r}#{k}"])
    end
  end
  req_class_paths2.each do |k, v|
    sequential_permission_names(clause, "*[#{v}]", @labels[k])
  end
end

#sequential_permission_children(block, idx) ⇒ Object



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

def sequential_permission_children(block, idx)
  req_class_paths.each do |k, v|
    REQS.each do |r|
      sequential_permission_names1(block, idx, "#{r}[#{v}]",
                                   @labels["#{r}#{k}"])
    end
  end
  req_class_paths2.each do |k, v|
    sequential_permission_names1(block, idx, "*[#{v}]", @labels[k])
  end
end

#sequential_permission_names(clause, klass, label) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/isodoc/ogc/xref.rb', line 18

def sequential_permission_names(clause, klass, label)
  c = Counter.new
  clause.xpath(ns(".//#{klass}#{FIRST_LVL_REQ}")).each do |t|
    next if t["id"].nil? || t["id"].empty?

    id = c.increment(t).print
    @anchors[t["id"]] = anchor_struct(id, t, label, klass,
                                      t["unnumbered"])
    reqt_suffix_label(t)
    permission_parts(t, label, klass)
    sequential_permission_children(t, id)
  end
end

#sequential_permission_names1(block, lbl, klass, label) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/isodoc/ogc/xref.rb', line 75

def sequential_permission_names1(block, lbl, klass, label)
  c = Counter.new
  block.xpath(ns("./#{klass}")).each do |t|
    next if t["id"].nil? || t["id"].empty?

    id = "#{lbl}#{hierfigsep}#{c.increment(t).print}"
    @anchors[t["id"]] = anchor_struct(id, t, label, klass,
                                      t["unnumbered"])
    permission_parts(t, label, klass)
    sequential_permission_children(t, id)
  end
end