lib/metanorma/modspec/validate.rb in mn-requirements-0.2.3 vs lib/metanorma/modspec/validate.rb in mn-requirements-0.3.0
- old
+ new
@@ -2,14 +2,16 @@
module Metanorma
class Requirements
class Modspec < Default
def validate(reqt, log)
+ @fatalerrors = []
@log ||= log
@ids ||= reqt_links(reqt.document)
reqt_cycles_validate
reqt_link_validate(reqt)
+ @fatalerrors
end
def nested_reqt?(reqt)
reqt.at("./ancestor::requirement | ./ancestor::recommendation | " \
"./ancestor::permission")
@@ -110,20 +112,29 @@
def reqt_links(docxml)
docxml.xpath("//requirement | //recommendation | //permission")
.each_with_object({ id: {}, class: {}, label: {} }) do |r, m|
next if nested_reqt?(r)
- reqt_links1(r, m)
+ reqt_links1(r, m, type2validate(r), reqt_links_struct(r))
end
end
- def reqt_links1(reqt, hash)
- type = type2validate(reqt)
- a = reqt_links_struct(reqt)
- hash[:id][reqt["id"]] = a
+ def reqt_links1(reqt, hash, type, struct)
+ hash[:id][reqt["id"]] = struct
hash[:class][type] ||= []
- hash[:class][type] << a
- hash[:label][a[:label]] = reqt["id"]
+ hash[:class][type] << struct
+ reqt_links1_label(reqt, hash, struct)
+ end
+
+ def reqt_links1_label(reqt, hash, struct)
+ return hash unless struct[:label]
+
+ if hash[:label][struct[:label]]
+ msg = "Modspec identifier #{struct[:label]} is used more than once"
+ @log.add("Requirements", reqt, msg)
+ @fatalerrors << msg
+ end
+ hash[:label][struct[:label]] = reqt["id"]
hash
end
def classif_tag(reqt, tag)
reqt.xpath("./classification[tag][value]")