module Metanorma
class Requirements
class Modspec < Default
REQT_TYPE_NORM = {
requirement: "general",
recommendation: "general",
permission: "general",
requirements_class: "class",
requirement_class: "class",
recommendation_class: "class",
permission_class: "class",
conformance_test: "verification",
conformance_class: "conformanceclass",
abstract_test: "abstracttest",
}.freeze
def requirement_type_cleanup(reqt)
ret = REQT_TYPE_NORM[reqt["type"]&.to_sym] or return
reqt["type"] = ret
end
def requirement_metadata_component_tags
%w(test-purpose test-method test-method-type conditions part description
reference step guidance) +
requirement_metadata_requirement_tags
end
def requirement_metadata_requirement_tags
%w(conformance-test conformance-class abstract-test requirement-class
recommendation-class permission-class requirement permission
recommendation)
end
def requirement_metadata1(reqt, dlist, ins)
ins1 = super
dlist.xpath("./dt").each do |e|
tag = e.text&.gsub(/ /, "-")&.downcase
next unless requirement_metadata_component_tags.include?(tag)
ins1.next = requirement_metadata1_component(e, tag)
ins1 = ins1.next
end
end
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
requirement_metadata_requirement_tags.include?(term.text) &&
!val.text.empty? and
val.children = "
#{c.children.to_xml}
" end end end end end