lib/isodoc/ogc/reqt.rb in metanorma-ogc-1.3.8 vs lib/isodoc/ogc/reqt.rb in metanorma-ogc-1.4.0
- old
+ new
@@ -18,13 +18,14 @@
else
"RecommendationTitle"
end
end
- def recommendation_header(r)
- h = r.add_child("<thead><tr><th scope='colgroup' colspan='2'></th></tr></thead>")
- recommendation_name(r, h.at(ns(".//th")))
+ def recommendation_header(recommend)
+ h = recommend.add_child("<thead><tr><th scope='colgroup' colspan='2'>"\
+ "</th></tr></thead>")
+ recommendation_name(recommend, h.at(ns(".//th")))
end
def recommendation_name(node, out)
b = out.add_child("<p class='#{recommendation_class(node)}'></p>").first
if name = node&.at(ns("./name"))&.remove
@@ -43,24 +44,57 @@
p = b.at(ns(".//p"))
p << label.children
end
def recommendation_attributes1(node)
- out = []
+ out = recommendation_attributes1_head(node, [])
+ out = recommendation_attributes1_component(node, out)
+ node.xpath(ns("./classification")).each do |c|
+ line = recommendation_attr_keyvalue(c, "tag", "value") and out << line
+ end
+ out
+ end
+
+ def recommendation_attributes1_head(node, out)
oblig = node["obligation"] and out << ["Obligation", oblig]
- subj = node&.at(ns("./subject"))&.remove&.children and out << [rec_subj(node), subj]
+ subj = node&.at(ns("./subject"))&.remove&.children and
+ out << [rec_subj(node), subj]
node.xpath(ns("./inherit")).each do |i|
out << ["Dependency", i.remove.children]
end
- node.xpath(ns("./classification")).each do |c|
- line = recommendation_attr_keyvalue(c, "tag", "value") and out << line
+ out
+ end
+
+ def strict_capitalize_phrase(str)
+ str.split(/ /).map do |w|
+ letters = w.chars
+ letters.first.upcase!
+ letters.join
+ end.join(" ")
+ end
+
+ def recommendation_attributes1_component(node, out)
+ node.xpath(ns("./component[not(@class = 'part')]")).each do |c|
+ out << case c["class"]
+ when "test-purpose" then ["Test Purpose", c.remove.children]
+ when "test-method" then ["Test Method", c.remove.children]
+ else [strict_capitalize_phrase(c["class"]), c.remove.children]
+ end
end
+ node.xpath(ns("./component[@class = 'part']")).each_with_index do |c, i|
+ out << [(i + "A".ord).chr.to_s, c.remove.children]
+ end
out
end
def rec_subj(node)
- node["type"] == "recommendclass" ? "Target Type" : "Subject"
+ case node["type_original"]
+ when "class" then "Target Type"
+ when "conformanceclass" then "Requirement Class"
+ when "verification", "abstracttest" then "Requirement"
+ else "Subject"
+ end
end
def recommendation_attr_keyvalue(node, key, value)
tag = node&.at(ns("./#{key}"))&.remove
value = node.at(ns("./#{value}"))&.remove
@@ -74,11 +108,12 @@
out.add_child("<tr><td>#{i[0]}</td><td>#{i[1]}</td></tr>")
end
end
def preserve_in_nested_table?(node)
- return true if %w(recommendation requirement permission table).include?(node.name)
+ return true if %w(recommendation requirement permission
+ table).include?(node.name)
false
end
def requirement_component_parse(node, out)
@@ -103,10 +138,11 @@
end
def recommendation_base(node, klass)
node.name = "table"
node["class"] = klass
+ node["type_original"] = node["type"]
node["type"] = recommend_class(node)
end
def recommendation_parse1(node, klass)
recommendation_base(node, klass)
@@ -117,9 +153,10 @@
node.elements.each do |n|
next if %w(thead tbody).include?(n.name)
requirement_component_parse(n, b)
end
+ node.delete("type_original")
end
def recommendation_to_table(docxml)
docxml.xpath(ns("//recommendation")).each do |r|
recommendation_parse1(r, "recommendation")