Class: IsoDoc::Ogc::Xref

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

Constant Summary collapse

FIGURE_NO_CLASS =
".//figure[not(@class)]".freeze
LISTING =
<<~XPATH.freeze
  .//figure[@class = 'pseudocode'] | .//sourcecode[not(ancestor::example)]
XPATH

Instance Method Summary collapse

Instance Method Details

#clause_order_annex(_docxml) ⇒ Object



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

def clause_order_annex(_docxml)
  if  @doctype == "engineering-report"
    [
      { path: @klass.bibliography_xpath },
      { path: "//annex", multi: true },
    ]
  else super
  end
end

#clause_order_back(_docxml) ⇒ Object



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

def clause_order_back(_docxml)
  if @doctype == "engineering-report"
    [
      { path: "//indexsect", multi: true },
      { path: "//colophon/*", multi: true },
    ]
  else super
  end
end

#clause_order_main(docxml) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/isodoc/ogc/xref.rb', line 7

def clause_order_main(docxml)
  ret = [{ path: "//clause[@type = 'scope']" },
         { path: "//clause[@type = 'conformance']" },
         { path: @klass.norm_ref_xpath }]
  a = ["//sections/terms | //sections/clause[descendant::terms]",
       "//sections/definitions | " \
       "//sections/clause[descendant::definitions][not(descendant::terms)]",
       @klass.middle_clause(docxml)]
  ret + if @doctype == "engineering-report"
          [{ path: a.join(" | "), multi: true }]
        else
          [{ path: a[0] }, { path: a[1] }, { path: a[2], multi: true }]
        end
end

#hierarchical_asset_names(clause, num) ⇒ Object



130
131
132
133
# File 'lib/isodoc/ogc/xref.rb', line 130

def hierarchical_asset_names(clause, num)
  super
  hierarchical_sourcecode_names(clause, num)
end

#hierarchical_sourcecode_names(clauses, num) ⇒ Object



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

def hierarchical_sourcecode_names(clauses, num)
  c = Counter.new
  nodeSet(clauses).each do |clause|
  clause.xpath(ns(LISTING)).noblank.each do |t|
    @anchors[t["id"]] =
      anchor_struct(#"#{num}#{hier_separator}#{c.increment(t).print}", 
                    hiersemx(clause, num, c.increment(t), t),
                    t, @labels["sourcecode"],
                    "sourcecode", { unnumb:t["unnumbered"] })
  end
  end
end

#middle_section_asset_names(doc) ⇒ Object



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

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

#preface_anchor_names(xml) ⇒ Object



52
53
54
55
# File 'lib/isodoc/ogc/xref.rb', line 52

def preface_anchor_names(xml)
  @prefacenum = 0
  super
end

#preface_names(clause) ⇒ Object



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

def preface_names(clause)
  clause.nil? || clause["type"] == "toc" and return
  @prefacenum += 1
  pref = semx(clause, preface_number(@prefacenum, 1))
  @anchors[clause["id"]] =
    { label: pref, level: 1,  type: "clause",
      xref: semx(clause, clause_title(clause), "title") }
  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, parentnum, num, level) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/isodoc/ogc/xref.rb', line 69

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

#preface_number(num, level) ⇒ Object



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

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

#sequential_asset_names(clause, container: false) ⇒ Object



113
114
115
116
# File 'lib/isodoc/ogc/xref.rb', line 113

def sequential_asset_names(clause, container: false)
  super
  sequential_sourcecode_names(clause, container: container)
end

#sequential_permission_bodyx(id, block, label, klass, model, container: false) ⇒ Object

KILL



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

def sequential_permission_bodyx(id, block, label, klass, model, container: false)
  @anchors[block["id"]] = model.postprocess_anchor_struct(
    block, anchor_struct(id, container ? block : nil,
                         label, klass, block["unnumbered"])
  )
  model.permission_parts(block, id, label, klass).each do |n|
    @anchors[n[:id]] = anchor_struct(n[:number], n[:elem], n[:label],
                                     n[:klass], { unnumb: false, container: container })
  end
end

#sequential_sourcecode_names(clause, container: false) ⇒ Object



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

def sequential_sourcecode_names(clause, container: false)
  c = Counter.new
  clause.xpath(ns(LISTING)).noblank.each do |t|
    c.increment(t)
    @anchors[t["id"]] = anchor_struct(
      c.print, t,
      @labels["sourcecode"], "sourcecode",
      { unnumb: t["unnumbered"], container: container}
    )
  end
end