Class: Metanorma::Requirements::Modspec

Inherits:
Default
  • Object
show all
Defined in:
lib/metanorma/modspec/xrefs.rb,
lib/metanorma/modspec/isodoc.rb,
lib/metanorma/modspec/cleanup.rb,
lib/metanorma/modspec/modspec.rb,
lib/metanorma/modspec/validate.rb,
lib/metanorma/modspec/reqt_label.rb

Constant Summary collapse

CLASS2LABEL =
{
  general: "Requirement",
  verification: "Conformance test",
  class: "Requirement class",
  conformanceclass: "Conformance class",
}.freeze

Constants inherited from Default

Default::REQS

Instance Method Summary collapse

Methods inherited from Default

#attr_code, #csv_split, #dl_to_attrs, #dl_to_elems, #initialize, #l10n, #noko, #ns, #recommendation_attr_parse, #recommendation_labels, #req_classif_parse, #reqt_attrs, #reqt_dl_to_classif, #reqt_dl_to_classif1, #reqt_dl_to_classif2, #reqt_metadata_node?, #reqt_subpart?, #reqt_subpart_attrs, #requirement, #requirement_classification, #requirement_description_cleanup1, #requirement_description_wrap, #requirement_descriptions_cleanup, #requirement_elems, #requirement_identifier_cleanup, #requirement_inherit_cleanup, #requirement_inherit_insert, #requirement_inherit_insert1, #requirement_metadata1_attrs, #requirement_metadata1_set_insert, #requirement_metadata1_tags, #requirement_subpart, #wrap_in_para

Constructor Details

This class inherits a constructor from Metanorma::Requirements::Default

Instance Method Details

#children_to_class(reqt, childclass, parentclass) ⇒ Object



74
75
76
77
78
79
80
81
82
# File 'lib/metanorma/modspec/validate.rb', line 74

def children_to_class(reqt, childclass, parentclass)
  return unless type2validate(reqt) == childclass

  r = @ids[:id][reqt["id"]]
  (r[:label] && @ids[:class][parentclass]&.any? do |x|
     x[:child].include?(r[:label])
   end) and return
  log_reqt(r, childclass, parentclass)
end

#class_to_children(reqt, type, childclass) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/metanorma/modspec/validate.rb', line 66

def class_to_children(reqt, type, childclass)
  return unless type2validate(reqt) == type

  r = @ids[:id][reqt["id"]]
  !r[:child].empty? and return
  log_reqt(r, type, childclass)
end

#conformance_to_reqt(reqt, reqtclass, confclass) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/metanorma/modspec/validate.rb', line 56

def conformance_to_reqt(reqt, reqtclass, confclass)
  return unless type2validate(reqt) == confclass

  r = @ids[:id][reqt["id"]]
  (r[:subject] && @ids[:class][reqtclass]&.any? do |x|
     r[:subject] == x[:label]
   end) and return
  log_reqt(r, confclass, reqtclass)
end

#init_lookups(doc) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/metanorma/modspec/reqt_label.rb', line 26

def init_lookups(doc)
  return if @init_lookups

  @init_lookups = true
  @reqtlabels = reqtlabels(doc)
  @reqt_ids = reqt_ids(doc)
  @reqt_links_class = reqt_links_class(doc)
  @reqt_links_test = reqt_links_test(doc)
end

#inject_crossreference_reqt?(node, label) ⇒ Boolean

embedded reqts xref to reqts via label lookup

Returns:

  • (Boolean)


44
45
46
47
# File 'lib/metanorma/modspec/reqt_label.rb', line 44

def inject_crossreference_reqt?(node, label)
  !node.ancestors("requirement, recommendation, permission").empty? and
    @reqtlabels[label]
end

#log_reqt(reqt, leftclass, rightclass) ⇒ Object



40
41
42
43
44
# File 'lib/metanorma/modspec/validate.rb', line 40

def log_reqt(reqt, leftclass, rightclass)
  @log.add("Requirements", reqt[:elem],
           "#{CLASS2LABEL[leftclass.to_sym]} #{reqt[:label] || reqt[:id]} "\
           "has no corresponding #{CLASS2LABEL[rightclass.to_sym]}")
end

#nested_reqt?(reqt) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
# File 'lib/metanorma/modspec/validate.rb', line 10

def nested_reqt?(reqt)
  reqt.at("./ancestor::requirement | ./ancestor::recommendation | "\
          "./ancestor::permission")
end

#permission_parts(block, block_id, label, klass) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/metanorma/modspec/xrefs.rb', line 47

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

    m << { id: c["id"], number: l10n("#{block_id} #{(i + 'A'.ord).chr}"),
           elem: c, label: label, klass: klass }
  end
end

#postprocess_anchor_struct(block, anchor) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/metanorma/modspec/xrefs.rb', line 57

def postprocess_anchor_struct(block, anchor)
  super
  anchor[:xref_bare] = anchor[:xref]
  if l = block.at(ns("./identifier"))&.text
    anchor[:xref] += l10n(": ") + "<tt>#{l}</tt>"
  end
  anchor
end

#preserve_in_nested_table?(node) ⇒ Boolean

Returns:

  • (Boolean)


162
163
164
165
# File 'lib/metanorma/modspec/isodoc.rb', line 162

def preserve_in_nested_table?(node)
  %w(recommendation requirement permission
     table ol dl ul).include?(node.name)
end

#rec_subj(node) ⇒ Object



201
202
203
204
205
206
# File 'lib/metanorma/modspec/isodoc.rb', line 201

def rec_subj(node)
  case node["type"]
  when "class" then @labels["modspec"]["targettype"]
  else @labels["default"]["subject"]
  end
end

#rec_target(node) ⇒ Object



208
209
210
211
212
213
214
215
# File 'lib/metanorma/modspec/isodoc.rb', line 208

def rec_target(node)
  case node["type"]
  when "class" then @labels["modspec"]["targettype"]
  when "conformanceclass" then @labels["modspec"]["requirementclass"]
  when "verification", "abstracttest" then @labels["default"]["requirement"]
  else @labels["modspec"]["target"]
  end
end

#recommend_class(node) ⇒ Object



217
218
219
220
221
222
223
# File 'lib/metanorma/modspec/isodoc.rb', line 217

def recommend_class(node)
  case node["type"]
  when "verification", "abstracttest" then "recommendtest"
  when "class", "conformanceclass" then "recommendclass"
  else "recommend"
  end
end

#recommend_component_label(node) ⇒ Object



232
233
234
235
236
237
238
239
240
# File 'lib/metanorma/modspec/isodoc.rb', line 232

def recommend_component_label(node)
  c = case node["class"]
      when "test-purpose" then "Test purpose"
      when "test-method" then "Test method"
      else node["class"]
      end
  @labels["default"][c] || @labels["modspec"][c] ||
    Metanorma::Utils.strict_capitalize_first(c)
end

#recommend_name_class(node) ⇒ Object



225
226
227
228
229
230
# File 'lib/metanorma/modspec/isodoc.rb', line 225

def recommend_name_class(node)
  if %w(verification abstracttest).include?(node["type"])
    "RecommendationTestTitle"
  else "RecommendationTitle"
  end
end

#recommend_title(node, out) ⇒ Object



68
69
70
71
72
# File 'lib/metanorma/modspec/isodoc.rb', line 68

def recommend_title(node, out)
  label = node.at(ns("./identifier")) or return
  out.add_child("<tr><td scope='colgroup' colspan='2'>"\
                "<tt>#{label.children.to_xml}</tt></td>")
end

#recommendation_attr_keyvalue(node, key, value) ⇒ Object



147
148
149
150
151
152
153
154
# File 'lib/metanorma/modspec/isodoc.rb', line 147

def recommendation_attr_keyvalue(node, key, value)
  tag = node.at(ns("./#{key}"))
  value = node.at(ns("./#{value}"))
  (tag && value && !%w(target
                       indirect-dependency).include?(tag.text)) or
    return nil
  [tag.text.capitalize, value.children]
end

#recommendation_attributes(node, out) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/metanorma/modspec/isodoc.rb', line 59

def recommendation_attributes(node, out)
  ins = out.add_child("<tbody></tbody>").first
  recommend_title(node, ins)
  recommendation_attributes1(node).each do |i|
    ins.add_child("<tr><td>#{i[0]}</td><td>#{i[1]}</td></tr>")
  end
  ins
end

#recommendation_attributes1(node) ⇒ Object



74
75
76
77
78
79
80
81
# File 'lib/metanorma/modspec/isodoc.rb', line 74

def recommendation_attributes1(node)
  ret = recommendation_attributes1_head(node, [])
  node.xpath(ns("./classification")).each do |c|
    line = recommendation_attr_keyvalue(c, "tag",
                                        "value") and ret << line
  end
  ret
end

#recommendation_attributes1_component(node, out) ⇒ Object



140
141
142
143
144
145
# File 'lib/metanorma/modspec/isodoc.rb', line 140

def recommendation_attributes1_component(node, out)
  node = recommendation_steps(node)
  id = node["id"] ? " id='#{node['id']}'" : ""
  out << "<tr#{id}><td>#{node['label']}</td><td>#{node.children}</td></tr>"
  out
end

#recommendation_attributes1_dependencies(node, head) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/metanorma/modspec/isodoc.rb', line 111

def recommendation_attributes1_dependencies(node, head)
  node.xpath(ns("./inherit")).each do |i|
    head << [@labels["modspec"]["dependency"],
             recommendation_id(i.children.to_xml)]
  end
  node.xpath(ns("./classification[tag = 'indirect-dependency']/value"))
    .each do |v|
    xref = recommendation_id(v.children.to_xml) and
      head << [@labels["modspec"]["indirectdependency"], xref]
  end
  head
end

#recommendation_attributes1_head(node, head) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/metanorma/modspec/isodoc.rb', line 83

def recommendation_attributes1_head(node, head)
  oblig = node["obligation"] and
    head << [@labels["default"]["obligation"], oblig]
  subj = node.at(ns("./subject"))&.children and
    head << [rec_subj(node), subj]
  node.xpath(ns("./classification[tag = 'target']/value")).each do |v|
    xref = recommendation_id(v.text) and head << [
      rec_target(node), xref
    ]
  end
  head += recommendation_backlinks(node)
  recommendation_attributes1_dependencies(node, head)
end


97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/metanorma/modspec/isodoc.rb', line 97

def recommendation_backlinks(node)
  ret = []
  id = node.at(ns("./identifier")) or return ret
  %w(general class).include?(node["type"]) and
    xref = recommendation_link_test(id.text) and
    ret << [@labels["modspec"]["conformancetest"], xref]
  ret
  (node["type"].nil? || node["type"].empty? ||
  node["type"] == "verification") and
    xref = recommendation_link_class(id.text) and
    ret << [@labels["modspec"]["included_in"], xref]
  ret
end

#recommendation_base(node, _klass) ⇒ Object



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

def recommendation_base(node, _klass)
  out = node.document.create_element("table")
  out.default_namespace = node.namespace.href
  %w(id keep-with-next keep-lines-together unnumbered).each do |x|
    out[x] = node[x] if node[x]
  end
  out["class"] = "modspec"
  out["type"] = recommend_class(node)
  recommendation_component_labels(node)
  out
end

#recommendation_class_label(node) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/metanorma/modspec/reqt_label.rb', line 49

def recommendation_class_label(node)
  case node["type"]
  when "verification" then @labels["modspec"]["#{node.name}test"]
  when "class" then @labels["modspec"]["#{node.name}class"]
  when "abstracttest" then @labels["modspec"]["abstracttest"]
  when "conformanceclass" then @labels["modspec"]["conformanceclass"]
  else
    case node.name
    when "recommendation" then @labels["default"]["recommendation"]
    when "requirement" then @labels["default"]["requirement"]
    when "permission" then @labels["default"]["permission"]
    end
  end
end

#recommendation_component_labels(node) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/metanorma/modspec/isodoc.rb', line 24

def recommendation_component_labels(node)
  node.xpath(ns("./component[@class = 'part']")).each_with_index do |c, i|
    c["label"] = (i + "A".ord).chr.to_s
  end
  node.xpath(ns("./component[not(@class = 'part')]")).each do |c|
    c["label"] = recommend_component_label(c)
  end
end

#recommendation_header(reqt, out) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/metanorma/modspec/isodoc.rb', line 33

def recommendation_header(reqt, out)
  n = recommendation_name(reqt, nil)
  x = if reqt.ancestors("requirement, recommendation, permission").empty?
        "<thead><tr><th scope='colgroup' colspan='2'>"\
          "<p class='#{recommend_name_class(reqt)}'>#{n}</p>"\
          "</th></tr></thead>"
      else
        "<thead><tr><td>#{recommendation_class_label(reqt)}</td>"\
          "<td>#{n}</td></tr></thead>"
      end
  out << x
  out
end

#recommendation_id(ident) ⇒ Object



115
116
117
118
# File 'lib/metanorma/modspec/reqt_label.rb', line 115

def recommendation_id(ident)
  test = @reqt_ids[ident&.strip] or return ident&.strip
  "<xref target='#{test[:id]}'>#{test[:lbl]}</xref>"
end

#recommendation_label(elem, type, xrefs) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/metanorma/modspec/reqt_label.rb', line 4

def recommendation_label(elem, type, xrefs)
  @xrefs ||= xrefs.dup
  init_lookups(elem.document)

  label = elem.at(ns("./identifier"))&.text
  if inject_crossreference_reqt?(elem, label)
    recommendation_label_xref(elem, label, xrefs)
  else
    type = recommendation_class_label(elem)
    super
  end
end

#recommendation_label_xref(elem, label, xrefs) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/metanorma/modspec/reqt_label.rb', line 17

def recommendation_label_xref(elem, label, xrefs)
  id = @reqtlabels[label]
  number = xrefs.anchor(id, :xref, false)
  number.nil? and return type
  elem.ancestors("requirement, recommendation, permission").empty? and
    return number
  "<xref target='#{id}'>#{number}</xref>"
end


110
111
112
113
# File 'lib/metanorma/modspec/reqt_label.rb', line 110

def recommendation_link_class(ident)
  test = @reqt_links_class[ident&.strip] or return nil
  "<xref target='#{test[:id]}'>#{test[:lbl]}</xref>"
end


88
89
90
91
# File 'lib/metanorma/modspec/reqt_label.rb', line 88

def recommendation_link_test(ident)
  test = @reqt_links_test[ident&.strip] or return nil
  "<xref target='#{test[:id]}'>#{test[:lbl]}</xref>"
end

#recommendation_name(node, _out) ⇒ Object



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

def recommendation_name(node, _out)
  ret = ""
  name = node.at(ns("./name")) and ret += name.children.to_xml
  title = node.at(ns("./title"))
  return ret unless title &&
    node.ancestors("requirement, recommendation, permission").empty?

  ret += l10n(": ") unless !name || name.text.empty?
  ret += title.children.to_xml
  ret
end

#recommendation_steps(node) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/metanorma/modspec/isodoc.rb', line 124

def recommendation_steps(node)
  node.elements.each { |e| recommendation_steps(e) }
  return node unless node.at(ns("./component[@class = 'step']"))

  d = node.at(ns("./component[@class = 'step']"))
  id = d["id"] ? " id='#{d['id']}'" : ""
  d = d.replace("<ol class='steps'><li#{id}>#{d.children.to_xml}</li></ol>")
    .first
  node.xpath(ns("./component[@class = 'step']")).each do |f|
    id = f["id"] ? " id='#{f['id']}'" : ""
    f = f.replace("<li#{id}>#{f.children.to_xml}</li>").first
    d << f
  end
  node
end

#req_class_pathsObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/metanorma/modspec/xrefs.rb', line 4

def req_class_paths
  [
    { klass: "permissionclass", label: @labels["modspec"]["permissionclass"],
      xpath: "permission[@type = 'class']" },
    { klass: "requirementclass", label: @labels["modspec"]["requirementclass"],
      xpath: "requirement[@type = 'class']" },
    { klass: "recommendationclass", label: @labels["modspec"]["recommendationclass"],
      xpath: "recommendation[@type = 'class']" },
    { klass: "permissiontest", label: @labels["modspec"]["permissiontest"],
      xpath: "permission[@type = 'verification']" },
    { klass: "recommendationtest", label: @labels["modspec"]["recommendationtest"],
      xpath: "recommendation[@type = 'verification']" },
    { klass: "requirementtest", label: @labels["modspec"]["requirementtest"],
      xpath: "requirement[@type = 'verification']" },
    { klass: "abstracttest", label: @labels["modspec"]["abstracttest"],
      xpath: "permission[@type = 'abstracttest']" },
    { klass: "abstracttest", label: @labels["modspec"]["abstracttest"],
      xpath: "requirement[@type = 'abstracttest']" },
    { klass: "abstracttest", label: @labels["modspec"]["abstracttest"],
      xpath: "recommendation[@type = 'abstracttest']" },
    { klass: "conformanceclass", label: @labels["modspec"]["conformanceclass"],
      xpath: "permission[@type = 'conformanceclass']" },
    { klass: "conformanceclass", label: @labels["modspec"]["conformanceclass"],
      xpath: "requirement[@type = 'conformanceclass']" },
    { klass: "conformanceclass", label: @labels["modspec"]["conformanceclass"],
      xpath: "recommendation[@type = 'conformanceclass']" },
    { klass: "permission", label: @labels["default"]["permission"],
      xpath: "permission[not(@type = 'verification' or @type = 'class' "\
             "or @type = 'abstracttest' or @type = 'conformanceclass')]" },
    { klass: "recommendation", label: @labels["default"]["recommendation"],
      xpath: "recommendation[not(@type = 'verification' or "\
             "@type = 'class' or @type = 'abstracttest' or "\
             "@type = 'conformanceclass')]" },
    { klass: "requirement", label: @labels["default"]["requirement"],
      xpath: "requirement[not(@type = 'verification' or @type = 'class' "\
             "or @type = 'abstracttest' or @type = 'conformanceclass')]" },
  ]
end

#req_nested_class_pathsObject



43
44
45
# File 'lib/metanorma/modspec/xrefs.rb', line 43

def req_nested_class_paths
  req_class_paths
end

#reqt_component_type(node) ⇒ Object



156
157
158
159
160
# File 'lib/metanorma/modspec/isodoc.rb', line 156

def reqt_component_type(node)
  klass = node.name
  klass == "component" and klass = node["class"]
  "requirement-#{klass}"
end

#reqt_dl(node, out) ⇒ Object



181
182
183
184
185
186
187
188
189
# File 'lib/metanorma/modspec/isodoc.rb', line 181

def reqt_dl(node, out)
  node.xpath(ns("./dt")).each do |dt|
    dd = dt.next_element
    dd&.name == "dd" or next
    out.add_child("<tr><td>#{dt.children.to_xml}</td>"\
                  "<td>#{dd.children.to_xml}</td></tr>")
  end
  out
end

#reqt_ids(docxml) ⇒ Object



64
65
66
67
68
69
70
71
# File 'lib/metanorma/modspec/reqt_label.rb', line 64

def reqt_ids(docxml)
  docxml.xpath(ns("//requirement | //recommendation | //permission"))
    .each_with_object({}) do |r, m|
      id = r.at(ns("./identifier")) or next
      m[id.text] =
        { id: r["id"], lbl: @xrefs.anchor(r["id"], :xref, false) }
    end
end


15
16
17
18
19
20
21
22
23
24
25
# File 'lib/metanorma/modspec/validate.rb', line 15

def reqt_link_validate(reqt)
  return if nested_reqt?(reqt)

  reqt_to_conformance(reqt, "general", "verification")
  reqt_to_conformance(reqt, "class", "conformanceclass")
  conformance_to_reqt(reqt, "general", "verification")
  conformance_to_reqt(reqt, "class", "conformanceclass")
  class_to_children(reqt, "class", "general")
  class_to_children(reqt, "conformanceclass", "verification")
  children_to_class(reqt, "verification", "conformanceclass")
end


84
85
86
87
88
89
90
91
# File 'lib/metanorma/modspec/validate.rb', line 84

def reqt_links(docxml)
  docxml.xpath("//requirement | //recommendation | //permission")
    .each_with_object({ id: {}, class: {} }) do |r, m|
      next if nested_reqt?(r)

      reqt_links1(r, m)
    end
end

#reqt_links1(reqt, hash) ⇒ Object



93
94
95
96
97
98
99
# File 'lib/metanorma/modspec/validate.rb', line 93

def reqt_links1(reqt, hash)
  type = type2validate(reqt)
  hash[:id][reqt["id"]] = reqt_links_struct(reqt)
  hash[:class][type] ||= []
  hash[:class][type] << hash[:id][reqt["id"]]
  hash
end


93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/metanorma/modspec/reqt_label.rb', line 93

def reqt_links_class(docxml)
  docxml.xpath(ns("//requirement | //recommendation | //permission"))
    .each_with_object({}) do |r, m|
      next unless %w(class conformanceclass).include?(r["type"])

      id = r.at(ns("./identifier")) or next
      r.xpath(ns("./requirement | ./recommendation | ./permission"))
        .each do |r1|
        id1 = r1.at(ns("./identifier")) or next
        lbl = @xrefs.anchor(@reqt_ids[id.text.strip][:id], :xref, false)
        next unless lbl

        m[id1.text] = { lbl: lbl, id: r["id"] }
      end
    end
end


101
102
103
104
105
106
107
108
# File 'lib/metanorma/modspec/validate.rb', line 101

def reqt_links_struct(reqt)
  { id: reqt["id"], elem: reqt, label: reqt.at("./identifier")&.text,
    subject: reqt.at("./classification[tag = 'target']/value")&.text,
    child: reqt.xpath("./requirement | ./recommendation | ./permission")
      .map do |r|
             r.at("./identifier")&.text
           end }
end


73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/metanorma/modspec/reqt_label.rb', line 73

def reqt_links_test(docxml)
  docxml.xpath(ns("//requirement | //recommendation | //permission"))
    .each_with_object({}) do |r, m|
      next unless %w(conformanceclass
                     verification).include?(r["type"])

      subj = r.at(ns("./classification[tag = 'target']/value"))
      id = r.at(ns("./identifier")) or next
      lbl = @xrefs.anchor(@reqt_ids[id.text.strip][:id], :xref, false)
      next unless subj && lbl

      m[subj.text] = { lbl: lbl, id: r["id"] }
    end
end

#reqt_to_conformance(reqt, reqtclass, confclass) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/metanorma/modspec/validate.rb', line 46

def reqt_to_conformance(reqt, reqtclass, confclass)
  return unless type2validate(reqt) == reqtclass

  r = @ids[:id][reqt["id"]]
  (r[:label] && @ids[:class][confclass]&.any? do |x|
     x[:subject] == r[:label]
   end) and return
  log_reqt(r, reqtclass, confclass)
end

#reqtlabels(doc) ⇒ Object



36
37
38
39
40
41
# File 'lib/metanorma/modspec/reqt_label.rb', line 36

def reqtlabels(doc)
  doc.xpath(ns("//requirement | //recommendation | //permission"))
    .each_with_object({}) do |r, m|
      l = r.at(ns("./identifier"))&.text and m[l] = r["id"]
    end
end

#requirement_component_parse(node, out) ⇒ Object



167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/metanorma/modspec/isodoc.rb', line 167

def requirement_component_parse(node, out)
  return out if node["exclude"] == "true"

  node.elements.size == 1 && node.first_element_child.name == "dl" and
    return reqt_dl(node.first_element_child, out)
  node.name == "component" and
    return recommendation_attributes1_component(node, out)
  id = node["id"] ? " id='#{node['id']}'" : ""
  out.add_child("<tr#{id}><td colspan='2'></td></tr>").first
    .at(ns(".//td")) <<
    (preserve_in_nested_table?(node) ? node : node.children)
  out
end

#requirement_metadata1(reqt, dlist, ins) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/metanorma/modspec/cleanup.rb', line 21

def requirement_metadata1(reqt, dlist, ins)
  ins1 = super
  dlist.xpath("./dt").each do |e|
    tag = e&.text&.gsub(/ /, "-")&.downcase
    next unless .include? tag

    ins1.next = requirement_metadata1_component(e, tag)
    ins1 = ins1.next
  end
end

#requirement_metadata1_component(term, tag) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/metanorma/modspec/cleanup.rb', line 32

def requirement_metadata1_component(term, tag)
  val = term.at("./following::dd")
  val.name = tag
  val.xpath("./dl").each do |d|
    requirement_metadata1(val, d, d)
    d.remove
  end
  if REQS.include?(term.text) && !val.text.empty?
    val.children = "<identifier>#{val.text.strip}</identifier>"
  end
  val
end

#requirement_metadata_cleanup(reqt) ⇒ Object

separate from default model requirement_metadata_cleanup,

which extracts model

ogc into reqt



47
48
49
50
51
52
53
# File 'lib/metanorma/modspec/cleanup.rb', line 47

def (reqt)
  super
  (reqt)
  (reqt)
  requirement_subparts_to_blocks(reqt)
  requirement_target_identifiers(reqt)
end

#requirement_metadata_component_tagsObject



16
17
18
19
# File 'lib/metanorma/modspec/cleanup.rb', line 16

def 
  %w(test-purpose test-method test-method-type conditions part description
     reference step requirement permission recommendation)
end

#requirement_metadata_to_component(reqt) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/metanorma/modspec/cleanup.rb', line 61

def (reqt)
  reqt.xpath(".//test-method | .//test-purpose | .//conditions | "\
             ".//part | .//test-method-type | .//step | .//reference")
    .each do |c|
    c["class"] = c.name
    c.name = "component"
  end
end

#requirement_metadata_to_requirement(reqt) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/metanorma/modspec/cleanup.rb', line 70

def (reqt)
  reqt.xpath("./requirement | ./permission | ./recommendation")
    .each do |c|
    c["id"] = Metanorma::Utils::anchor_or_uuid
    c["model"] = reqt["model"] # all requirements must have a model
  end
end

#requirement_render1(node) ⇒ Object



7
8
9
10
# File 'lib/metanorma/modspec/isodoc.rb', line 7

def requirement_render1(node)
  init_lookups(node.document)
  requirement_table_cleanup(super)
end

#requirement_subparts_to_blocks(reqt) ⇒ Object



78
79
80
81
82
83
84
85
# File 'lib/metanorma/modspec/cleanup.rb', line 78

def requirement_subparts_to_blocks(reqt)
  reqt.xpath(".//component | .//description").each do |c|
    next if %w(p ol ul dl table component description)
      .include?(c&.elements&.first&.name)

    c.children = "<p>#{c.children.to_xml}</p>"
  end
end

#requirement_table_cleanup(table) ⇒ Object



191
192
193
194
195
196
197
198
199
# File 'lib/metanorma/modspec/isodoc.rb', line 191

def requirement_table_cleanup(table)
  return table unless table["type"] == "recommendclass"

  table.xpath(ns("./tbody/tr/td/table")).each do |t|
    x = t.at(ns("./thead/tr")) or next
    t.parent.parent.replace(x)
  end
  table
end

#requirement_target_identifiers(reqt) ⇒ Object



55
56
57
58
59
# File 'lib/metanorma/modspec/cleanup.rb', line 55

def requirement_target_identifiers(reqt)
  reqt.xpath("./classification[tag = 'target']/value[link]").each do |v|
    v.children = v.at("./link/@target").text
  end
end

#requirement_type_cleanup(reqt) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/metanorma/modspec/cleanup.rb', line 4

def requirement_type_cleanup(reqt)
  reqt["type"] = case reqt["type"]
                 when "requirement", "recommendation", "permission"
                   "general"
                 when "requirements_class" then "class"
                 when "conformance_test" then "verification"
                 when "conformance_class" then "conformanceclass"
                 when "abstract_test" then "abstracttest"
                 else reqt["type"]
                 end
end

#type2validate(reqt) ⇒ Object



27
28
29
30
31
# File 'lib/metanorma/modspec/validate.rb', line 27

def type2validate(reqt)
  type = reqt["type"]
  type = "general" if type.nil? || type.empty?
  type
end

#validate(reqt, log) ⇒ Object



4
5
6
7
8
# File 'lib/metanorma/modspec/validate.rb', line 4

def validate(reqt, log)
  @log ||= log
  @ids ||= reqt_links(reqt.document)
  reqt_link_validate(reqt)
end