Class: Metanorma::Cc::Converter
- Inherits:
-
Generic::Converter
- Object
- Generic::Converter
- Metanorma::Cc::Converter
- Defined in:
- lib/metanorma/cc/converter.rb,
lib/metanorma/cc/validate_section.rb
Constant Summary collapse
- ONE_SYMBOLS_WARNING =
"Only one Symbols and Abbreviated "\ "Terms section in the standard".freeze
- NON_DL_SYMBOLS_WARNING =
"Symbols and Abbreviated Terms can "\ "only contain a definition list".freeze
- SEQ =
spec of permissible section sequence we skip normative references, it goes to end of list
[ { msg: "Initial section must be (content) Foreword", val: ["./self::foreword"], }, { msg: "Prefatory material must be followed by (clause) Scope", val: ["./self::introduction", "./self::clause[@type = 'scope']"], }, { msg: "Prefatory material must be followed by (clause) Scope", val: ["./self::clause[@type = 'scope']"], }, { msg: "Normative References must be followed by "\ "Terms and Definitions", val: ["./self::terms | .//terms"], }, ].freeze
- SECTIONS_XPATH =
"//foreword | //introduction | //sections/terms | .//annex | "\ "//sections/definitions | //sections/clause | "\ "//references[not(parent::clause)] | "\ "//clause[descendant::references][not(parent::clause)]".freeze
Instance Method Summary collapse
- #configuration ⇒ Object
- #doc_converter(node) ⇒ Object
- #html_converter(node) ⇒ Object
- #metadata_committee(node, xml) ⇒ Object
- #outputs(node, ret) ⇒ Object
- #pdf_converter(node) ⇒ Object
- #presentation_xml_converter(node) ⇒ Object
- #section_validate(doc) ⇒ Object
- #sections_sequence_validate(root) ⇒ Object
- #seqcheck(names, msg, accepted) ⇒ Object
- #style_warning(node, msg, text = nil) ⇒ Object
- #symbols_validate(root) ⇒ Object
Instance Method Details
#configuration ⇒ Object
15 16 17 |
# File 'lib/metanorma/cc/converter.rb', line 15 def configuration Metanorma::Cc.configuration end |
#doc_converter(node) ⇒ Object
55 56 57 |
# File 'lib/metanorma/cc/converter.rb', line 55 def doc_converter(node) IsoDoc::Cc::WordConvert.new(doc_extract_attributes(node)) end |
#html_converter(node) ⇒ Object
45 46 47 |
# File 'lib/metanorma/cc/converter.rb', line 45 def html_converter(node) IsoDoc::Cc::HtmlConvert.new(html_extract_attributes(node)) end |
#metadata_committee(node, xml) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/metanorma/cc/converter.rb', line 19 def (node, xml) return unless node.attr("technical-committee") xml.editorialgroup do |a| a.committee node.attr("technical-committee"), **attr_code(type: node.attr("technical-committee-type")) i = 2 while node.attr("technical-committee_#{i}") a.committee node.attr("technical-committee_#{i}"), **attr_code(type: node.attr("technical-committee-type_#{i}")) i += 1 end end end |
#outputs(node, ret) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/metanorma/cc/converter.rb', line 34 def outputs(node, ret) File.open("#{@filename}.xml", "w:UTF-8") { |f| f.write(ret) } presentation_xml_converter(node).convert("#{@filename}.xml") html_converter(node).convert("#{@filename}.presentation.xml", nil, false, "#{@filename}.html") doc_converter(node).convert("#{@filename}.presentation.xml", nil, false, "#{@filename}.doc") pdf_converter(node)&.convert("#{@filename}.presentation.xml", nil, false, "#{@filename}.pdf") end |
#pdf_converter(node) ⇒ Object
49 50 51 52 53 |
# File 'lib/metanorma/cc/converter.rb', line 49 def pdf_converter(node) return if node.attr("no-pdf") IsoDoc::Cc::PdfConvert.new(pdf_extract_attributes(node)) end |
#presentation_xml_converter(node) ⇒ Object
59 60 61 62 63 |
# File 'lib/metanorma/cc/converter.rb', line 59 def presentation_xml_converter(node) IsoDoc::Cc::PresentationXMLConvert .new(doc_extract_attributes(node) .merge(output_formats: ::Metanorma::Cc::Processor.new.output_formats)) end |
#section_validate(doc) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/metanorma/cc/validate_section.rb', line 7 def section_validate(doc) advisory = doc.root.at("//bibdata/ext[doctype = 'advisory']") symbols_validate(doc.root) unless advisory sections_sequence_validate(doc.root) unless advisory super end |
#sections_sequence_validate(root) ⇒ Object
72 73 74 75 76 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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/metanorma/cc/validate_section.rb', line 72 def sections_sequence_validate(root) names = root.xpath(SECTIONS_XPATH) names = seqcheck(names, SEQ[0][:msg], SEQ[0][:val]) n = names[0] names = seqcheck(names, SEQ[1][:msg], SEQ[1][:val]) if n&.at("./self::introduction") names = seqcheck(names, SEQ[2][:msg], SEQ[2][:val]) end names = seqcheck(names, SEQ[3][:msg], SEQ[3][:val]) n = names.shift if n&.at("./self::definitions") n = names.shift end if n.nil? || n.name != "clause" @log.add("Style", nil, "Document must contain at least one clause") end n&.at("./self::clause") || @log.add("Style", nil, "Document must contain clause after "\ "Terms and Definitions") n&.at("./self::clause[@type = 'scope']") && @log.add("Style", nil, "Scope must occur before Terms and Definitions") n = names.shift while n&.name == "clause" n&.at("./self::clause[@type = 'scope']") @log.add("Style", nil, "Scope must occur before Terms and Definitions") n = names.shift end unless %w(annex references).include? n&.name @log.add("Style", nil, "Only annexes and references can follow clauses") end while n&.name == "annex" n = names.shift if n.nil? @log.add("Style", nil, "Document must include (references) "\ "Normative References") end end n&.at("./self::references[@normative = 'true']") || @log.add("Style", nil, "Document must include (references) "\ "Normative References") n = names&.shift n&.at("./self::references[@normative = 'false']") || @log.add("Style", nil, "Final section must be (references) Bibliography") names.empty? || @log.add("Style", nil, "There are sections after the final Bibliography") end |
#seqcheck(names, msg, accepted) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/metanorma/cc/validate_section.rb', line 32 def seqcheck(names, msg, accepted) n = names.shift return [] if n.nil? test = accepted.map { |a| n.at(a) } if test.all?(&:nil?) @log.add("Style", nil, msg) end names end |
#style_warning(node, msg, text = nil) ⇒ Object
124 125 126 127 128 129 130 |
# File 'lib/metanorma/cc/validate_section.rb', line 124 def style_warning(node, msg, text = nil) return if @novalid w = msg w += ": #{text}" if text @log.add("Style", node, w) end |
#symbols_validate(root) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/metanorma/cc/validate_section.rb', line 20 def symbols_validate(root) f = root.xpath("//definitions") f.empty? && return (f.size == 1) || @log.add("Style", f.first, ONE_SYMBOLS_WARNING) f.first.elements.each do |e| unless e.name == "dl" @log.add("Style", f.first, NON_DL_SYMBOLS_WARNING) return end end end |