Class: Metanorma::Requirements::Modspec
- Defined in:
- lib/metanorma/modspec/log.rb,
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,
lib/metanorma/modspec/table_cleanup.rb
Defined Under Namespace
Classes: TSHash
Constant Summary collapse
- MODSPEC_LOG_MESSAGES =
{ # rubocop:disable Naming/VariableNumber "MODSPEC_1": { category: "Requirements", error: "Requirements linkage: %s %s has no corresponding %s", severity: 2 }, "MODSPEC_2": { category: "Requirements", error: "Requirements linkage: %s %s points to %s %s outside this document", severity: 2 }, "MODSPEC_3": { category: "Requirements", error: "Modspec identifier %s is used more than once", severity: 0 }, "MODSPEC_4": { category: "Requirements", error: "Cycle in Modspec linkages through %s: %s", severity: 2 }, }.freeze
- 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
- CLASS2LABEL =
{ general: "Requirement", verification: "Conformance test", class: "Requirement class", conformanceclass: "Conformance class", provision: "Provision", dependency: "Prerequisite", indirect_dependency: "Indirect prerequisite", implements: "Implemented provision", }.freeze
Constants inherited from Default
Instance Method Summary collapse
- #add_misc_container(xmldoc) ⇒ Object
- #add_misccontainer_anchor_aliases(xmldoc) ⇒ Object
- #cell2link(table) ⇒ Object
- #children_to_class(reqt, childclass, parentclass) ⇒ Object
- #class_to_children(reqt, type, childclass) ⇒ Object
- #classif_tag(reqt, tag) ⇒ Object
- #conflate_table_rows(trow) ⇒ Object
- #conflate_table_rows?(trow) ⇒ Boolean
- #conformance_to_reqt(reqt, reqtclass, confclass) ⇒ Object
-
#expand_xrefs_in_reqt(table) ⇒ Object
any xrefs not yet expanded out to rendering need to be expanded out, so that the identifier instances they contain can be truncated.
- #gather_consec_table_rows(trow, hdr) ⇒ Object
- #id_attr(node) ⇒ Object
-
#identifier2text(ident) ⇒ Object
allow case where identifier contains a link, which has not yet been converted to its target text.
- #init_lookups(doc) ⇒ Object
-
#initialize(options) ⇒ Modspec
constructor
A new instance of Modspec.
-
#inject_crossreference_reqt?(node, label) ⇒ Boolean
embedded reqts xref to reqts via label lookup.
- #log_reqt(reqt, leftclass, rightclass) ⇒ Object
- #log_reqt2(reqt, leftclass, target, rightclass) ⇒ Object
- #nested_reqt?(reqt) ⇒ Boolean
- #permission_parts(block, block_id, label, klass) ⇒ Object
- #plural_table_row_hdr(thdr) ⇒ Object
- #postprocess_anchor_struct(block, anchor) ⇒ Object
- #preserve_in_nested_table?(node) ⇒ Boolean
- #rec_subj(node) ⇒ Object
- #rec_target(node) ⇒ Object
- #recommend_class(node) ⇒ Object
- #recommend_component_label(node) ⇒ Object
- #recommend_name_class(node) ⇒ Object
- #recommend_title(node, out) ⇒ Object
- #recommendation_attr_keyvalue(node, key, value) ⇒ Object
- #recommendation_attributes(node, out) ⇒ Object
- #recommendation_attributes1(node) ⇒ Object
- #recommendation_attributes1_component(node, ret, out) ⇒ Object
- #recommendation_attributes1_dependencies(node, head) ⇒ Object
- #recommendation_attributes1_head(node, head) ⇒ Object
- #recommendation_attributes1_inherit(node, head) ⇒ Object
- #recommendation_attributes1_target(node, head) ⇒ Object
- #recommendation_attributes_dependencies2(node, head) ⇒ Object
- #recommendation_backlinks(node) ⇒ Object
- #recommendation_backlinks_class(node, id, ret) ⇒ Object
- #recommendation_backlinks_test(node, id, ret) ⇒ Object
- #recommendation_base(node, _klass) ⇒ Object
- #recommendation_class_label(node) ⇒ Object
- #recommendation_component_labels(node) ⇒ Object
- #recommendation_header(reqt, out) ⇒ Object
- #recommendation_id(ident) ⇒ Object
- #recommendation_label(elem, type, xrefs) ⇒ Object
- #recommendation_label_add(elem, _label, title) ⇒ Object
- #recommendation_label_caption_delim ⇒ Object
- #recommendation_label_xref(elem, label, xrefs, type) ⇒ Object
- #recommendation_labels(node) ⇒ Object
- #recommendation_link_class(ident) ⇒ Object
- #recommendation_link_test(ident) ⇒ Object
- #recommendation_steps(node, ret) ⇒ Object
- #req_class_paths ⇒ Object
- #req_nested_class_paths ⇒ Object
- #reqt_component_type(node) ⇒ Object
- #reqt_cycles_validate ⇒ Object
- #reqt_cycles_validate1(link) ⇒ Object
- #reqt_cycles_validate1_prep(link) ⇒ Object
- #reqt_cycles_validate_dependency ⇒ Object
- #reqt_dl(node, out) ⇒ Object
- #reqt_extract_id_base(reqt) ⇒ Object
- #reqt_extract_target(reqt) ⇒ Object
- #reqt_hierarchy_extract ⇒ Object
- #reqt_id_base(docxml) ⇒ Object
- #reqt_id_base_inherit(ret, class2reqt) ⇒ Object
- #reqt_id_base_init(docxml) ⇒ Object
- #reqt_ids(docxml) ⇒ Object
- #reqt_link_validate(reqt) ⇒ Object
- #reqt_links(docxml) ⇒ Object
- #reqt_links1(reqt, hash, type, struct) ⇒ Object
- #reqt_links1_label(reqt, hash, struct) ⇒ Object
-
#reqt_links_class(docxml) ⇒ Object
we have not implemented multiple levels of nesting of classes.
- #reqt_links_class1(id, parent_reqt, reqt, acc) ⇒ Object
- #reqt_links_struct(reqt) ⇒ Object
- #reqt_links_test(docxml) ⇒ Object
- #reqt_links_test1(reqt, acc) ⇒ Object
- #reqt_to_conformance(reqt, reqtclass, confclass) ⇒ Object
- #reqt_to_dependency(reqt) ⇒ Object
- #reqtlabels(doc) ⇒ Object
- #requirement_anchor_aliases(reqt) ⇒ Object
- #requirement_anchor_aliases_extract(reqt) ⇒ Object
- #requirement_anchor_identifier(reqt) ⇒ Object
- #requirement_component_parse(node, out) ⇒ Object
- #requirement_description_parse(node, ret, out) ⇒ Object
- #requirement_guidance_parse(node, out) ⇒ Object
- #requirement_identifier_cleanup(reqt) ⇒ Object
- #requirement_metadata1(reqt, dlist, ins) ⇒ Object
- #requirement_metadata1_component(term, tag) ⇒ Object
- #requirement_metadata1_component_val2id(val) ⇒ Object
-
#requirement_metadata_cleanup(reqt) ⇒ Object
- separate from default model requirement_metadata_cleanup, which extracts model
-
ogc into reqt.
- #requirement_metadata_component_tags ⇒ Object
- #requirement_metadata_requirement_tags ⇒ Object
- #requirement_metadata_to_component(reqt) ⇒ Object
- #requirement_metadata_to_requirement(reqt) ⇒ Object
- #requirement_metadata_to_requirement1(reqt) ⇒ Object
- #requirement_presentation(node, out) ⇒ Object
- #requirement_render1(node) ⇒ Object
- #requirement_subparts_to_blocks(reqt) ⇒ Object
- #requirement_table_cleanup(node, out) ⇒ Object
- #requirement_table_consec_rows_cleanup(_node, table) ⇒ Object
- #requirement_table_nested_cleanup(node, out, table) ⇒ Object
- #requirement_table_nested_cleanup_hdr(node) ⇒ Object
- #requirement_target_identifiers(reqt) ⇒ Object
- #requirement_type_cleanup(reqt) ⇒ Object
- #strip_id_base(elem, base) ⇒ Object
- #truncate_id_base_fmtxreflabel(node) ⇒ Object
- #truncate_id_base_in_reqt(table) ⇒ Object
- #truncate_id_base_in_reqt1(table, base) ⇒ Object
- #truncate_id_base_outside_reqts(docxml) ⇒ Object
- #truncate_id_base_outside_reqts1(xref, base) ⇒ Object
- #type2validate(reqt) ⇒ Object
- #uri?(string) ⇒ Boolean
- #validate(reqt, log) ⇒ Object
Methods inherited from Default
#attr_code, #copy_style_attributes, #csv_split, #descr_classif_extract, #descr_classif_render, #dl_to_attrs, #dl_to_elems, #l10n, #noko, #ns, #recommendation_attr_parse, #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_inherit_cleanup, #requirement_inherit_insert, #requirement_inherit_insert1, #requirement_metadata1_attrs, #requirement_metadata1_set_insert, #requirement_metadata1_tags, #requirement_render1_default, #requirement_render1_inline, #requirement_render1_inline_prep, #requirement_subpart, #semx_fmt_dup, #to_xml, #unwrap_para, #wrap_in_para
Constructor Details
#initialize(options) ⇒ Modspec
Returns a new instance of Modspec.
8 9 10 11 |
# File 'lib/metanorma/modspec/modspec.rb', line 8 def initialize() super @modspecidentifierbase = @parent.modspecidentifierbase end |
Instance Method Details
#add_misc_container(xmldoc) ⇒ Object
145 146 147 148 149 150 151 152 |
# File 'lib/metanorma/modspec/cleanup.rb', line 145 def add_misc_container(xmldoc) unless ins = xmldoc.at("//metanorma-extension") a = xmldoc.at("//termdocsource") || xmldoc.at("//bibdata") a.next = "<metanorma-extension/>" ins = xmldoc.at("//metanorma-extension") end ins end |
#add_misccontainer_anchor_aliases(xmldoc) ⇒ Object
154 155 156 157 158 159 160 161 162 |
# File 'lib/metanorma/modspec/cleanup.rb', line 154 def add_misccontainer_anchor_aliases(xmldoc) m = add_misc_container(xmldoc) x = ".//table[@anchor='_misccontainer_anchor_aliases']/tbody" unless ins = m.at(x) m << "<table anchor='_misccontainer_anchor_aliases' id='_#{UUIDTools::UUID.random_create}'><tbody/></table>" ins = m.at(x) end ins end |
#cell2link(table) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/metanorma/modspec/table_cleanup.rb', line 18 def cell2link(table) table.xpath(ns(".//td")).each do |td| td.elements.empty? || (td.elements.size == 1 && td.elements.first.name == "semx") or next uri?(td.text.strip) or next td.children = "<link target='#{td.text.strip}'>#{to_xml(td.children)}</link>" end end |
#children_to_class(reqt, childclass, parentclass) ⇒ Object
98 99 100 101 102 103 104 105 |
# File 'lib/metanorma/modspec/validate.rb', line 98 def children_to_class(reqt, childclass, parentclass) type2validate(reqt) == childclass or return 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
90 91 92 93 94 95 96 |
# File 'lib/metanorma/modspec/validate.rb', line 90 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 |
#classif_tag(reqt, tag) ⇒ Object
132 133 134 135 136 137 138 |
# File 'lib/metanorma/modspec/validate.rb', line 132 def classif_tag(reqt, tag) reqt.xpath("./classification[tag][value]") .each_with_object([]) do |c, m| c.at("./tag").text.casecmp(tag).zero? or next m << c.at("./value").text end end |
#conflate_table_rows(trow) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/metanorma/modspec/table_cleanup.rb', line 48 def conflate_table_rows(trow) th = trow.at(ns("./th")) hdr = plural_table_row_hdr(th) td = th.next_element id = td["id"] ? "<bookmark id='#{td['id']}'/>" : "" td.delete("id") res = [id + to_xml(td.children).strip] res += gather_consec_table_rows(trow, hdr) td.children = res.join("<br/>") end |
#conflate_table_rows?(trow) ⇒ Boolean
41 42 43 44 45 46 |
# File 'lib/metanorma/modspec/table_cleanup.rb', line 41 def conflate_table_rows?(trow) tr1 = trow.next or return tr1.name == "tr" or return th = trow.at(ns("./th"))&.text th && th == tr1.at(ns("./th"))&.text end |
#conformance_to_reqt(reqt, reqtclass, confclass) ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'lib/metanorma/modspec/validate.rb', line 80 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].include?(x[:label]) end and return log_reqt(r, confclass, reqtclass) end |
#expand_xrefs_in_reqt(table) ⇒ Object
any xrefs not yet expanded out to rendering need to be expanded out, so that the identifier instances they contain can be truncated
131 132 133 134 135 136 137 138 |
# File 'lib/metanorma/modspec/table_cleanup.rb', line 131 def (table) table.xpath(ns(".//xref[not(@style)][string-length() = 0]")) .each do |x| @xrefs.anchor(x["target"], :modspec, false) or next # modspec xrefs only ref = @xrefs.anchor(x["target"], :xref, false) or next x << ref end end |
#gather_consec_table_rows(trow, hdr) ⇒ Object
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/metanorma/modspec/table_cleanup.rb', line 66 def gather_consec_table_rows(trow, hdr) ret = [] trow.xpath("./following-sibling::xmlns:tr").each do |r| r.at(ns("./th"))&.text&.strip == hdr or break td = r.remove.at(ns("./td")) id = td["id"] ? "<bookmark id='#{td['id']}'/>" : "" ret << id + to_xml(td.children).strip end ret end |
#id_attr(node) ⇒ Object
154 155 156 157 |
# File 'lib/metanorma/modspec/isodoc.rb', line 154 def id_attr(node) id = node["id"] || node["original-id"] id ? " id='#{id}'" : "" end |
#identifier2text(ident) ⇒ Object
allow case where identifier contains a link, which has not yet been converted to its target text
89 90 91 92 93 94 |
# File 'lib/metanorma/modspec/cleanup.rb', line 89 def identifier2text(ident) m = ident.dup l = m.at("./link[normalize-space(.)='']") and l.replace(l["target"]) m.text.strip end |
#init_lookups(doc) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/metanorma/modspec/reqt_label.rb', line 37 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) @reqt_id_base = reqt_id_base(doc) truncate_id_base_outside_reqts(doc) end |
#inject_crossreference_reqt?(node, label) ⇒ Boolean
embedded reqts xref to reqts via label lookup
56 57 58 59 |
# File 'lib/metanorma/modspec/reqt_label.rb', line 56 def inject_crossreference_reqt?(node, label) !node.ancestors("requirement, recommendation, permission").empty? and @reqtlabels[label] end |
#log_reqt(reqt, leftclass, rightclass) ⇒ Object
51 52 53 54 |
# File 'lib/metanorma/modspec/validate.rb', line 51 def log_reqt(reqt, leftclass, rightclass) @log.add("MODSPEC_1", reqt[:elem], params: [CLASS2LABEL[leftclass.to_sym], reqt[:label] || reqt[:id], CLASS2LABEL[rightclass.to_sym]]) end |
#log_reqt2(reqt, leftclass, target, rightclass) ⇒ Object
56 57 58 59 |
# File 'lib/metanorma/modspec/validate.rb', line 56 def log_reqt2(reqt, leftclass, target, rightclass) @log.add("MODSPEC_2", reqt[:elem], params: [CLASS2LABEL[leftclass], reqt[:label] || reqt[:id], CLASS2LABEL[rightclass], target]) end |
#nested_reqt?(reqt) ⇒ Boolean
15 16 17 18 |
# File 'lib/metanorma/modspec/validate.rb', line 15 def nested_reqt?(reqt) reqt.at("./ancestor::requirement | ./ancestor::recommendation | " \ "./ancestor::permission") end |
#permission_parts(block, block_id, label, klass) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/metanorma/modspec/xrefs.rb', line 62 def (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 |
#plural_table_row_hdr(thdr) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/metanorma/modspec/table_cleanup.rb', line 59 def plural_table_row_hdr(thdr) th1 = thdr.at(ns("./semx")) || thdr hdr = th1.text th1.children = @i18n.inflect(hdr, number: "pl") hdr end |
#postprocess_anchor_struct(block, anchor) ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/metanorma/modspec/xrefs.rb', line 72 def postprocess_anchor_struct(block, anchor) super anchor[:xref_bare] = anchor[:xref] l = block.at(ns("./identifier")) and anchor[:xref] += l10n(": ") + "<tt><xref style='id' target='#{block['id']}'>#{to_xml semx_fmt_dup(l)}</xref></tt>" anchor[:modspec] = anchor[:xref] anchor end |
#preserve_in_nested_table?(node) ⇒ Boolean
206 207 208 209 |
# File 'lib/metanorma/modspec/isodoc.rb', line 206 def preserve_in_nested_table?(node) !%w(subject inherit identifier measurement-target specification verification import description component).include?(node.name) end |
#rec_subj(node) ⇒ Object
220 221 222 223 224 225 |
# File 'lib/metanorma/modspec/reqt_label.rb', line 220 def rec_subj(node) case node["type"] when "class" then @labels["modspec"]["targettype"] else @labels["default"]["subject"] end end |
#rec_target(node) ⇒ Object
227 228 229 230 231 232 233 234 |
# File 'lib/metanorma/modspec/reqt_label.rb', line 227 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
236 237 238 239 240 241 242 |
# File 'lib/metanorma/modspec/reqt_label.rb', line 236 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
251 252 253 254 255 256 257 258 259 |
# File 'lib/metanorma/modspec/reqt_label.rb', line 251 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
244 245 246 247 248 249 |
# File 'lib/metanorma/modspec/reqt_label.rb', line 244 def recommend_name_class(node) if %w(verification abstracttest).include?(node["type"]) "RecommendationTestTitle" else "RecommendationTitle" end end |
#recommend_title(node, out) ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'lib/metanorma/modspec/isodoc.rb', line 86 def recommend_title(node, out) label = node.at(ns("./identifier")) or return ret = <<~OUTPUT <tr><th>#{@labels['modspec']['identifier']}</th> <td><tt><modspec-ident>#{to_xml(semx_fmt_dup(label))}</modspec-ident></tt></td> OUTPUT out.add_child(ret) end |
#recommendation_attr_keyvalue(node, key, value) ⇒ Object
189 190 191 192 193 194 195 196 197 198 |
# File 'lib/metanorma/modspec/isodoc.rb', line 189 def recommendation_attr_keyvalue(node, key, value) tag = node.at(ns("./#{key}")) or return nil value = node.at(ns("./#{value}")) or return nil !%w(target indirect-dependency identifier-base implements).include?(tag.text.downcase) or return nil lbl = semx_fmt_dup(tag) lbl.children = Metanorma::Utils.strict_capitalize_first(lbl.text) [to_xml(lbl), semx_fmt_dup(value)] end |
#recommendation_attributes(node, out) ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/metanorma/modspec/isodoc.rb', line 77 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><th>#{i[0]}</th><td>#{i[1]}</td></tr>") end ins end |
#recommendation_attributes1(node) ⇒ Object
95 96 97 98 99 100 101 102 |
# File 'lib/metanorma/modspec/isodoc.rb', line 95 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, ret, out) ⇒ Object
180 181 182 183 184 185 186 187 |
# File 'lib/metanorma/modspec/isodoc.rb', line 180 def recommendation_attributes1_component(node, ret, out) node["class"] == "guidance" and return out ret = recommendation_steps(node, ret) out << "<tr#{id_attr(node)}><th>#{node['label']}</th>" \ "<td>#{to_xml(ret)}</td></tr>" node.delete("label") # inserted in recommendation_component_labels out end |
#recommendation_attributes1_dependencies(node, head) ⇒ Object
130 131 132 133 |
# File 'lib/metanorma/modspec/isodoc.rb', line 130 def recommendation_attributes1_dependencies(node, head) head = recommendation_attributes1_inherit(node, head) recommendation_attributes_dependencies2(node, head) end |
#recommendation_attributes1_head(node, head) ⇒ Object
104 105 106 107 108 109 110 111 112 |
# File 'lib/metanorma/modspec/isodoc.rb', line 104 def recommendation_attributes1_head(node, head) oblig = node["obligation"] and head << [@labels["default"]["obligation"], oblig] subj = node.at(ns("./subject")) and head << [rec_subj(node), semx_fmt_dup(subj)] head = recommendation_attributes1_target(node, head) head += recommendation_backlinks(node) recommendation_attributes1_dependencies(node, head) end |
#recommendation_attributes1_inherit(node, head) ⇒ Object
135 136 137 138 139 140 141 |
# File 'lib/metanorma/modspec/isodoc.rb', line 135 def recommendation_attributes1_inherit(node, head) node.xpath(ns("./inherit")).each do |i| head << [@labels["modspec"]["dependency"], recommendation_id(semx_fmt_dup(i))] end head end |
#recommendation_attributes1_target(node, head) ⇒ Object
114 115 116 117 118 119 120 121 |
# File 'lib/metanorma/modspec/isodoc.rb', line 114 def recommendation_attributes1_target(node, head) node.xpath(ns("./classification[tag][value]")).each do |c| c.at(ns("./tag")).text.casecmp("target").zero? or next xref = recommendation_id(semx_fmt_dup(c.at(ns("./value")))) and head << [rec_target(node), xref] end head end |
#recommendation_attributes_dependencies2(node, head) ⇒ Object
143 144 145 146 147 148 149 150 151 152 |
# File 'lib/metanorma/modspec/isodoc.rb', line 143 def recommendation_attributes_dependencies2(node, head) %w(indirect-dependency implements).each do |x| node.xpath(ns("./classification[tag][value]")).each do |c| c.at(ns("./tag")).text.casecmp(x).zero? or next xref = recommendation_id(semx_fmt_dup(c.at(ns("./value")))) and head << [@labels["modspec"][x.delete("-")], xref] end end head end |
#recommendation_backlinks(node) ⇒ Object
123 124 125 126 127 128 |
# File 'lib/metanorma/modspec/isodoc.rb', line 123 def recommendation_backlinks(node) ret = [] id = node.at(ns("./identifier")) or return ret ret = recommendation_backlinks_test(node, id, ret) recommendation_backlinks_class(node, id, ret) end |
#recommendation_backlinks_class(node, id, ret) ⇒ Object
180 181 182 183 184 185 186 |
# File 'lib/metanorma/modspec/reqt_label.rb', line 180 def recommendation_backlinks_class(node, id, 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_backlinks_test(node, id, ret) ⇒ Object
172 173 174 175 176 177 178 |
# File 'lib/metanorma/modspec/reqt_label.rb', line 172 def recommendation_backlinks_test(node, id, ret) (%w(general class).include?(node["type"]) && xref = recommendation_link_test(id.text)) or return ret lbl = node["type"] == "general" ? "conformancetest" : "conformanceclass" ret << [@labels["modspec"][lbl], xref] ret end |
#recommendation_base(node, _klass) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/metanorma/modspec/isodoc.rb', line 23 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 node["original-id"] = node["id"] node["id"] = "_#{UUIDTools::UUID.random_create}" out["type"] = recommend_class(node) recommendation_component_labels(node) out end |
#recommendation_class_label(node) ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/metanorma/modspec/reqt_label.rb', line 61 def recommendation_class_label(node) node["class"] and return node["class"] case node["type"] when "class" then @labels["modspec"]["#{node.name}class"] when "verification" then @labels["modspec"]["conformancetest"] when "abstracttest", "conformanceclass" @labels["modspec"][node["type"]] else @labels["default"][node.name] end end |
#recommendation_component_labels(node) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/metanorma/modspec/isodoc.rb', line 36 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
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/metanorma/modspec/isodoc.rb', line 45 def recommendation_header(reqt, out) n = to_xml(reqt.at(ns("./fmt-name")))&.strip x = if reqt.ancestors("requirement, recommendation, permission").empty? <<~THEAD <thead><tr><th scope='colgroup' colspan='2'><p class='#{recommend_name_class(reqt)}'>#{n}</p></th></tr></thead> THEAD else "<thead><tr><th>#{recommendation_class_label(reqt)}</th>" \ "<td>#{n}</td></tr></thead>" end out << x out end |
#recommendation_id(ident) ⇒ Object
164 165 166 167 168 169 170 |
# File 'lib/metanorma/modspec/reqt_label.rb', line 164 def recommendation_id(ident) id = to_xml(ident.children) test = @reqt_ids[id&.strip] or return to_xml(ident) #require "debug"; binding.b if test.include?("<xref") #"<xref target='#{test[:id]}'>#{test[:lbl]}</xref>" test[:lbl] end |
#recommendation_label(elem, type, xrefs) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/metanorma/modspec/reqt_label.rb', line 15 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, type) else type = recommendation_class_label(elem) super end end |
#recommendation_label_add(elem, _label, title) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/metanorma/modspec/isodoc.rb', line 59 def recommendation_label_add(elem, _label, title) title or return "" r = recommendation_label_caption_delim title and r += "<semx element='title' source='#{elem['id']}'>#{title}</semx>" r end |
#recommendation_label_caption_delim ⇒ Object
67 68 69 |
# File 'lib/metanorma/modspec/isodoc.rb', line 67 def recommendation_label_caption_delim "<span class='fmt-caption-delim'>: </span>" end |
#recommendation_label_xref(elem, label, xrefs, type) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/metanorma/modspec/reqt_label.rb', line 27 def recommendation_label_xref(elem, label, xrefs, type) id = @reqtlabels[label] number = xrefs.anchor(id, :modspec, false) number.nil? and return "<span class='fmt-element-name'>#{type}</span>" elem.ancestors("requirement, recommendation, permission").empty? and return number #"<xref target='#{id}'>#{number}</xref>" number end |
#recommendation_labels(node) ⇒ Object
71 72 73 74 75 |
# File 'lib/metanorma/modspec/isodoc.rb', line 71 def recommendation_labels(node) node.ancestors("requirement, recommendation, permission").empty? or return [nil, nil] super end |
#recommendation_link_class(ident) ⇒ Object
158 159 160 161 162 |
# File 'lib/metanorma/modspec/reqt_label.rb', line 158 def recommendation_link_class(ident) test = @reqt_links_class[ident&.strip] or return nil #"<xref target='#{test[:id]}'>#{test[:lbl]}</xref>" test[:lbl] end |
#recommendation_link_test(ident) ⇒ Object
105 106 107 108 109 |
# File 'lib/metanorma/modspec/reqt_label.rb', line 105 def recommendation_link_test(ident) test = @reqt_links_test[ident&.strip] or return nil #"<xref target='#{test[:id]}'>#{test[:lbl]}</xref>" test[:lbl] end |
#recommendation_steps(node, ret) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/metanorma/modspec/isodoc.rb', line 159 def recommendation_steps(node, ret) ret.elements.each_with_index do |e, i| e1 = nil e.name == "component" && e["class"] == "step" and e1 = e.replace(semx_fmt_dup(node.elements[i])) recommendation_steps(node.elements[i], e1 || e) end node.name == "component" && node["class"] == "step" and ret["inlist"] = "true" d = ret.at(ns("./semx[@inlist]")) or return ret d.delete("inlist") d = d.replace("<ol class='steps'><li#{id_attr(d)}>" \ "#{to_xml(d)}</li></ol>").first ret.xpath(ns("./semx[@inlist]")).each do |f| f.delete("inlist") f = f.replace("<li#{id_attr(f)}>#{to_xml(f)}</li>").first d << f end ret end |
#req_class_paths ⇒ Object
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# 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"]["conformancetest"], xpath: "permission[@type = 'verification']" }, { klass: "recommendationtest", label: @labels["modspec"]["conformancetest"], xpath: "recommendation[@type = 'verification']" }, { klass: "requirementtest", label: @labels["modspec"]["conformancetest"], 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_paths ⇒ Object
58 59 60 |
# File 'lib/metanorma/modspec/xrefs.rb', line 58 def req_nested_class_paths req_class_paths end |
#reqt_component_type(node) ⇒ Object
200 201 202 203 204 |
# File 'lib/metanorma/modspec/isodoc.rb', line 200 def reqt_component_type(node) klass = node.name klass == "component" and klass = node["class"] "requirement-#{klass}" end |
#reqt_cycles_validate ⇒ Object
150 151 152 153 154 155 156 |
# File 'lib/metanorma/modspec/validate.rb', line 150 def reqt_cycles_validate @cycles_validated and return @cycles_validated = true %i(child dependency indirect_dependency implements).each do |x| reqt_cycles_validate1(x) end end |
#reqt_cycles_validate1(link) ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/metanorma/modspec/validate.rb', line 158 def reqt_cycles_validate1(link) arr = reqt_cycles_validate1_prep(link) TSort.each_strongly_connected_component( lambda { |&b| arr.tsort_each_node(&b) }, lambda { |n, &b| arr.tsort_each_child(n, &b) }, ) do |path| path.size == 1 and next @log.add("MODSPEC_4", nil, params: [link, (path << path.first).join(" => ")]) end end |
#reqt_cycles_validate1_prep(link) ⇒ Object
170 171 172 173 174 |
# File 'lib/metanorma/modspec/validate.rb', line 170 def reqt_cycles_validate1_prep(link) arr = TSHash.new(@ids[:id].values) arr.link = link arr end |
#reqt_cycles_validate_dependency ⇒ Object
195 |
# File 'lib/metanorma/modspec/validate.rb', line 195 def reqt_cycles_validate_dependency; end |
#reqt_dl(node, out) ⇒ Object
263 264 265 266 267 268 269 270 271 |
# File 'lib/metanorma/modspec/isodoc.rb', line 263 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><th>#{to_xml(dt.children)}</th>" \ "<td>#{to_xml(dd.children)}</td></tr>") end out end |
#reqt_extract_id_base(reqt) ⇒ Object
99 100 101 102 103 |
# File 'lib/metanorma/modspec/reqt_label.rb', line 99 def reqt_extract_id_base(reqt) reqt.xpath(ns("./classification[tag][value]")).detect do |x| x.at(ns("./tag")).text.casecmp("identifier-base").zero? end&.at(ns("./value")) end |
#reqt_extract_target(reqt) ⇒ Object
93 94 95 96 97 |
# File 'lib/metanorma/modspec/reqt_label.rb', line 93 def reqt_extract_target(reqt) reqt.xpath(ns("./classification[tag][value]")).detect do |x| x.at(ns("./tag")).text.casecmp("target").zero? end&.at(ns("./value")) end |
#reqt_hierarchy_extract ⇒ Object
131 132 133 134 135 136 |
# File 'lib/metanorma/modspec/reqt_label.rb', line 131 def reqt_hierarchy_extract @reqt_links_class.each_with_object({}) do |(k, v), m| m[v[:id]] ||= [] m[v[:id]] << @reqt_ids[k][:id] end end |
#reqt_id_base(docxml) ⇒ Object
151 152 153 154 155 156 |
# File 'lib/metanorma/modspec/reqt_label.rb', line 151 def reqt_id_base(docxml) ret = reqt_id_base_init(docxml) ret = reqt_id_base_inherit(ret, reqt_hierarchy_extract) @modspecidentifierbase or return ret ret.each_key { |k| ret[k] ||= @modspecidentifierbase } end |
#reqt_id_base_inherit(ret, class2reqt) ⇒ Object
142 143 144 145 146 147 148 149 |
# File 'lib/metanorma/modspec/reqt_label.rb', line 142 def reqt_id_base_inherit(ret, class2reqt) ret.each_key do |k| class2reqt[k]&.each do |k1| ret[k1] ||= ret[k] end end ret end |
#reqt_id_base_init(docxml) ⇒ Object
138 139 140 |
# File 'lib/metanorma/modspec/reqt_label.rb', line 138 def reqt_id_base_init(docxml) docxml.reqt_iter { |r, m| m[r["id"]] = reqt_extract_id_base(r)&.text } end |
#reqt_ids(docxml) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/metanorma/modspec/reqt_label.rb', line 72 def reqt_ids(docxml) docxml.reqt_iter do |r, m| id = r.at(ns("./identifier")) or next m[id.text] = { id: r["id"], lbl: @xrefs.anchor(r["id"], :modspec, false) } end end |
#reqt_link_validate(reqt) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/metanorma/modspec/validate.rb', line 20 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") reqt_to_dependency(reqt) end |
#reqt_links(docxml) ⇒ Object
107 108 109 110 111 112 113 114 |
# File 'lib/metanorma/modspec/validate.rb', line 107 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, type2validate(r), reqt_links_struct(r)) end end |
#reqt_links1(reqt, hash, type, struct) ⇒ Object
116 117 118 119 120 121 |
# File 'lib/metanorma/modspec/validate.rb', line 116 def reqt_links1(reqt, hash, type, struct) hash[:id][reqt["id"]] = struct hash[:class][type] ||= [] hash[:class][type] << struct reqt_links1_label(reqt, hash, struct) end |
#reqt_links1_label(reqt, hash, struct) ⇒ Object
123 124 125 126 127 128 129 130 |
# File 'lib/metanorma/modspec/validate.rb', line 123 def reqt_links1_label(reqt, hash, struct) struct[:label] or return hash if hash[:label][struct[:label]] @log.add("MODSPEC_3", reqt, params: [struct[:label]]) end hash[:label][struct[:label]] = reqt["id"] hash end |
#reqt_links_class(docxml) ⇒ Object
we have not implemented multiple levels of nesting of classes
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/metanorma/modspec/reqt_label.rb', line 112 def reqt_links_class(docxml) docxml.reqt_iter do |r, m| %w(class conformanceclass).include?(r["type"]) or next id = r.at(ns("./identifier")) or next r.xpath(ns("./requirement | ./recommendation | ./permission")) .each do |r1| m = reqt_links_class1(id, r, r1, m) end end end |
#reqt_links_class1(id, parent_reqt, reqt, acc) ⇒ Object
123 124 125 126 127 128 129 |
# File 'lib/metanorma/modspec/reqt_label.rb', line 123 def reqt_links_class1(id, parent_reqt, reqt, acc) id1 = reqt.at(ns("./identifier")) or return acc lbl = @xrefs.anchor(@reqt_ids[id.text.strip][:id], :modspec, false) lbl or return acc acc[id1.text] = { lbl: lbl, id: parent_reqt["id"] } acc end |
#reqt_links_struct(reqt) ⇒ Object
140 141 142 143 144 145 146 147 148 |
# File 'lib/metanorma/modspec/validate.rb', line 140 def reqt_links_struct(reqt) { id: reqt["anchor"], elem: reqt, label: reqt.at("./identifier")&.text, subject: classif_tag(reqt, "target"), child: reqt.xpath("./requirement | ./recommendation | ./permission") .map { |r| r.at("./identifier")&.text }, dependency: reqt.xpath("./inherit").map(&:text), indirect_dependency: classif_tag(reqt, "indirect-dependency"), implements: classif_tag(reqt, "implements") } end |
#reqt_links_test(docxml) ⇒ Object
80 81 82 |
# File 'lib/metanorma/modspec/reqt_label.rb', line 80 def reqt_links_test(docxml) docxml.reqt_iter { |r, m| reqt_links_test1(r, m) } end |
#reqt_links_test1(reqt, acc) ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'lib/metanorma/modspec/reqt_label.rb', line 84 def reqt_links_test1(reqt, acc) %w(conformanceclass verification).include?(reqt["type"]) or return subj = reqt_extract_target(reqt) id = reqt.at(ns("./identifier")) or return lbl = @xrefs.anchor(@reqt_ids[id.text.strip][:id], :modspec, false) (subj && lbl) or return acc[subj.text] = { lbl: lbl, id: reqt["id"] } end |
#reqt_to_conformance(reqt, reqtclass, confclass) ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/metanorma/modspec/validate.rb', line 70 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].include?(r[:label]) end and return log_reqt(r, reqtclass, confclass) end |
#reqt_to_dependency(reqt) ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/metanorma/modspec/validate.rb', line 61 def reqt_to_dependency(reqt) r = @ids[:id][reqt["id"]] %i(dependency indirect_dependency implements).each do |x| r[x].each do |d| @ids[:label][d] or log_reqt2(r, :provision, d, x) end end end |
#reqtlabels(doc) ⇒ Object
49 50 51 52 53 |
# File 'lib/metanorma/modspec/reqt_label.rb', line 49 def reqtlabels(doc) doc.reqt_iter do |r, m| l = r.at(ns("./identifier"))&.text and m[l] = r["id"] end end |
#requirement_anchor_aliases(reqt) ⇒ Object
164 165 166 167 168 169 |
# File 'lib/metanorma/modspec/cleanup.rb', line 164 def requirement_anchor_aliases(reqt) ids = requirement_anchor_aliases_extract(reqt) or return table = add_misccontainer_anchor_aliases(reqt.document) alias_id = reqt["anchor"] or return table << "<tr><th>#{alias_id}</th>#{ids.join}</tr>" end |
#requirement_anchor_aliases_extract(reqt) ⇒ Object
171 172 173 174 175 176 177 178 179 |
# File 'lib/metanorma/modspec/cleanup.rb', line 171 def requirement_anchor_aliases_extract(reqt) x = reqt.xpath("./identifier") x.empty? and return x.each_with_object([]) do |i, m| m << "<td>#{i.text}</td>" alias_id = ::Metanorma::Utils.to_ncname(i.text) alias_id != i.text and m << "<td>#{alias_id}</td>" end end |
#requirement_anchor_identifier(reqt) ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/metanorma/modspec/cleanup.rb', line 78 def requirement_anchor_identifier(reqt) (!reqt["anchor"] || Metanorma::Utils::guid_anchor?(reqt["anchor"])) or return id = reqt.at("./identifier") or return anchor = identifier2text(id) anchor.empty? and return reqt["anchor"] = anchor end |
#requirement_component_parse(node, out) ⇒ Object
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/metanorma/modspec/isodoc.rb', line 211 def requirement_component_parse(node, out) node["exclude"] == "true" and return out ret = semx_fmt_dup(node) descr_classif_render(node, ret) id = node["id"] || node["original-id"] id and attr = " id='#{id}'" preserve = preserve_in_nested_table?(node) if id == node["id"] if node["original-id"] attr = " id='#{node['original-id']}'" else node["original-id"] = node["id"] end node.delete("id") end if preserve n = Nokogiri::XML::Node.new(node.name, node.document) node.attributes.each { |k, v| n[k] = v } node.children.empty? or n << ret ret = n end ret.elements.size == 1 && ret.first_element_child.name == "dl" and return reqt_dl(ret.first_element_child, out) node.name == "component" and return recommendation_attributes1_component(node, ret, out) node.name == "description" and return requirement_description_parse(node, ret, out) out.add_child("<tr#{attr}><td colspan='2'></td></tr>").first .at(ns(".//td")) << (%(permission requirement recommendation).include?(node.name) ? node.dup : ret) out end |
#requirement_description_parse(node, ret, out) ⇒ Object
243 244 245 246 247 248 249 250 |
# File 'lib/metanorma/modspec/isodoc.rb', line 243 def requirement_description_parse(node, ret, out) lbl = "description" recommend_class(node.parent) == "recommend" and lbl = "statement" out << "<tr><th>#{@labels['modspec'][lbl]}</th>" \ "<td>#{to_xml(ret)}</td></tr>" out end |
#requirement_guidance_parse(node, out) ⇒ Object
252 253 254 255 256 257 258 259 260 261 |
# File 'lib/metanorma/modspec/isodoc.rb', line 252 def requirement_guidance_parse(node, out) ins = out.at(ns("./fmt-provision/table/tbody")) origs = node.xpath(ns("./component[@class = 'guidance']")) out.xpath(ns("./component[@class = 'guidance']")).each_with_index do |f, i| f.delete("label") ins << "<tr#{id_attr(f)}><th>#{@labels['modspec']['guidance']}</th>" \ "<td>#{to_xml(semx_fmt_dup(origs[i]))}</td></tr>" end out end |
#requirement_identifier_cleanup(reqt) ⇒ Object
181 182 183 184 |
# File 'lib/metanorma/modspec/cleanup.rb', line 181 def requirement_identifier_cleanup(reqt) super requirement_anchor_aliases(reqt) end |
#requirement_metadata1(reqt, dlist, ins) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/metanorma/modspec/cleanup.rb', line 34 def (reqt, dlist, ins) ins1 = super dlist.xpath("./dt").each do |e| tag = e.text&.tr(" ", "-")&.downcase tag = "description" if tag == "statement" next unless .include?(tag) ins1.next = (e, tag) ins1 = ins1.next end end |
#requirement_metadata1_component(term, tag) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/metanorma/modspec/cleanup.rb', line 46 def (term, tag) val = term.at("./following::dd") val.name = tag val.xpath("./dl").each do |d| (val, d, d) d.remove end .include?(term.text) or return val (val) end |
#requirement_metadata1_component_val2id(val) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/metanorma/modspec/cleanup.rb', line 58 def (val) if val.at(".//link") && val.text.strip.empty? val.children = "<identifier>#{val.at('.//link')['target']}</identifier>" elsif !val.text.strip.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
69 70 71 72 73 74 75 76 |
# File 'lib/metanorma/modspec/cleanup.rb', line 69 def (reqt) super (reqt) (reqt) requirement_subparts_to_blocks(reqt) requirement_target_identifiers(reqt) requirement_anchor_identifier(reqt) end |
#requirement_metadata_component_tags ⇒ Object
22 23 24 25 26 |
# File 'lib/metanorma/modspec/cleanup.rb', line 22 def %w(test-purpose test-method test-method-type conditions part description statement reference step guidance) + end |
#requirement_metadata_requirement_tags ⇒ Object
28 29 30 31 32 |
# File 'lib/metanorma/modspec/cleanup.rb', line 28 def %w(conformance-test conformance-class abstract-test requirement-class recommendation-class permission-class requirement permission recommendation) end |
#requirement_metadata_to_component(reqt) ⇒ Object
105 106 107 108 109 110 111 112 113 |
# File 'lib/metanorma/modspec/cleanup.rb', line 105 def (reqt) xpath = - %w(statement description) - reqt.xpath(xpath.map { |x| ".//#{x}" }.join(" | ")).each do |c| c["class"] = c.name c.name = "component" end end |
#requirement_metadata_to_requirement(reqt) ⇒ Object
115 116 117 118 119 120 121 122 123 |
# File 'lib/metanorma/modspec/cleanup.rb', line 115 def (reqt) xpath = reqt.xpath(xpath.map { |x| "./#{x}" }.join(" | ")).each do |c| # c["id"] = Metanorma::Utils::anchor_or_uuid c["id"] = "_#{UUIDTools::UUID.random_create}" c["model"] = reqt["model"] # all requirements must have a model (c) end end |
#requirement_metadata_to_requirement1(reqt) ⇒ Object
125 126 127 128 129 130 131 132 133 134 |
# File 'lib/metanorma/modspec/cleanup.rb', line 125 def (reqt) reqt["type"] = reqt.name.sub(/-/, "_") reqt.name = case reqt.name when "recommendation-class", "recommendation" then "recommendation" when "permission-class", "permission" then "permission" else "requirement" end requirement_type_cleanup(reqt) end |
#requirement_presentation(node, out) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/metanorma/modspec/isodoc.rb', line 16 def requirement_presentation(node, out) ret = node.document.create_element("fmt-provision") ret << out out = ret super end |
#requirement_render1(node) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/metanorma/modspec/isodoc.rb', line 8 def requirement_render1(node) init_lookups(node.document) ret = requirement_guidance_parse(node, super) out = requirement_table_cleanup(node, ret) truncate_id_base_fmtxreflabel(out) out end |
#requirement_subparts_to_blocks(reqt) ⇒ Object
136 137 138 139 140 141 142 143 |
# File 'lib/metanorma/modspec/cleanup.rb', line 136 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>#{to_xml(c.children)}</p>" end end |
#requirement_table_cleanup(node, out) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/metanorma/modspec/table_cleanup.rb', line 6 def requirement_table_cleanup(node, out) table = out.at(ns("./fmt-provision/table")) table = requirement_table_nested_cleanup(node, out, table) requirement_table_consec_rows_cleanup(node, table) node.ancestors("requirement, recommendation, permission").empty? and truncate_id_base_in_reqt(table) cell2link(table) table["class"] = "modspec" # deferred; node["class"] is labelling class out.xpath(ns("./fmt-name | ./fmt-identifier")).each(&:remove) out end |
#requirement_table_consec_rows_cleanup(_node, table) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/metanorma/modspec/table_cleanup.rb', line 34 def requirement_table_consec_rows_cleanup(_node, table) table.xpath(ns("./tbody/tr")).each do |tr| conflate_table_rows?(tr) or next conflate_table_rows(tr) end end |
#requirement_table_nested_cleanup(node, out, table) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/metanorma/modspec/table_cleanup.rb', line 77 def requirement_table_nested_cleanup(node, out, table) rows = [] table.xpath(ns("./tbody/tr/td/*/fmt-provision/table")) .sort_by do |t| [t.at(ns(".//fmt-name//span[@class = 'fmt-element-name']"))&.text, t.at(ns(".//fmt-name//semx[@element = 'autonum']"))&.text&.to_i] end.each do |t| x = t.at(ns("./thead/tr")) or next x.at(ns("./th")).children = requirement_table_nested_cleanup_hdr(node) f = x.at(ns("./td/fmt-name")) and f.parent.children = to_xml(f.children).strip td = x.at(ns("./td")) td["id"] = t["original-id"] || t["id"] if desc = t.at(ns("./tbody/tr/td/semx[@element = 'description']")) p = desc.at(ns("./p")) and p.replace(p.children) td << " #{to_xml(desc)}" end rows << x end table.xpath(ns("./tbody/tr[./td/*/fmt-provision/table]")) .each_with_index do |t, i| t.replace(rows[i]) end out.xpath(ns("./*/fmt-provision")).each(&:remove) table end |
#requirement_table_nested_cleanup_hdr(node) ⇒ Object
105 106 107 108 109 |
# File 'lib/metanorma/modspec/table_cleanup.rb', line 105 def requirement_table_nested_cleanup_hdr(node) label = "provision" node["type"] == "conformanceclass" and label = "conformancetest" @i18n.get["requirements"]["modspec"][label] end |
#requirement_target_identifiers(reqt) ⇒ Object
96 97 98 99 100 101 102 103 |
# File 'lib/metanorma/modspec/cleanup.rb', line 96 def requirement_target_identifiers(reqt) reqt.xpath("./classification[tag][value/link]").each do |c| %w(target indirect-dependency implements identifier-base) .include?(c.at("./tag").text.downcase) or next v = c.at("./value[link]") v.children = v.at("./link/@target").text end end |
#requirement_type_cleanup(reqt) ⇒ Object
17 18 19 20 |
# File 'lib/metanorma/modspec/cleanup.rb', line 17 def requirement_type_cleanup(reqt) ret = REQT_TYPE_NORM[reqt["type"]&.to_sym] or return reqt["type"] = ret end |
#strip_id_base(elem, base) ⇒ Object
111 112 113 114 |
# File 'lib/metanorma/modspec/table_cleanup.rb', line 111 def strip_id_base(elem, base) base.nil? and return elem.children to_xml(elem.children).delete_prefix(base) end |
#truncate_id_base_fmtxreflabel(node) ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/metanorma/modspec/reqt_label.rb', line 198 def truncate_id_base_fmtxreflabel(node) f = node.at(ns("./fmt-xref-label")) or return x = f.at(ns(".//xref[@style = 'id']")) or return if @reqt_id_base[x["target"]] && @modspecidentifierbase f.next = f.dup x = f.next_element.at(ns(".//xref[@style = 'id']")) f.next_element["container"] = 'modspec-provision' truncate_id_base_outside_reqts1(x, @modspecidentifierbase) end if base = @reqt_id_base[node["original-id"] || node["id"]] f.next = f.dup x = f.next_element.at(ns(".//xref[@style = 'id']")) f["container"] = node["original-id"] || node["id"] truncate_id_base_outside_reqts1(x, base) end end |
#truncate_id_base_in_reqt(table) ⇒ Object
140 141 142 143 144 |
# File 'lib/metanorma/modspec/table_cleanup.rb', line 140 def truncate_id_base_in_reqt(table) base = @reqt_id_base[table["id"]] (table) truncate_id_base_in_reqt1(table, base) end |
#truncate_id_base_in_reqt1(table, base) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/metanorma/modspec/table_cleanup.rb', line 116 def truncate_id_base_in_reqt1(table, base) table.xpath(ns(".//xref[@style = 'id']")).each do |x| @reqt_id_base[x["target"]] or next # is a modspec requirement n = x.at(ns("./semx")) and x = n x.children = strip_id_base(x, base) end table.xpath(ns(".//modspec-ident")).each do |x| n = x.at(ns("./semx")) || x n.children = strip_id_base(n, base) n != x and x.replace(n) end end |
#truncate_id_base_outside_reqts(docxml) ⇒ Object
188 189 190 191 192 193 194 195 196 |
# File 'lib/metanorma/modspec/reqt_label.rb', line 188 def truncate_id_base_outside_reqts(docxml) @modspecidentifierbase or return (docxml.xpath(ns("//xref[@style = 'id']")) - docxml .xpath(ns("//requirement//xref | //permission//xref | " \ "//recommendation//xref"))).each do |x| @reqt_id_base[x["target"]] or next # is a modspec requirement truncate_id_base_outside_reqts1(x, @modspecidentifierbase) end end |
#truncate_id_base_outside_reqts1(xref, base) ⇒ Object
215 216 217 218 |
# File 'lib/metanorma/modspec/reqt_label.rb', line 215 def truncate_id_base_outside_reqts1(xref, base) xref = xref.at(ns("./semx")) || xref xref.children = to_xml(xref.children).delete_prefix(base) end |
#type2validate(reqt) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/metanorma/modspec/validate.rb', line 33 def type2validate(reqt) type = reqt["type"] type = "general" if type.nil? || type.empty? type = "verification" if type == "abstracttest" type end |
#uri?(string) ⇒ Boolean
27 28 29 30 31 32 |
# File 'lib/metanorma/modspec/table_cleanup.rb', line 27 def uri?(string) uri = URI.parse(string) %w(http https).include?(uri.scheme) rescue URI::BadURIError, URI::InvalidURIError false end |
#validate(reqt, log) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/metanorma/modspec/validate.rb', line 7 def validate(reqt, log) @log ||= log @log&.add_msg(MODSPEC_LOG_MESSAGES) @ids ||= reqt_links(reqt.document) reqt_cycles_validate reqt_link_validate(reqt) end |