Sha256: 180dab1ab80779e445bf53f3b149f9950d18a0e41a8146d98721e1288b9cc244

Contents?: true

Size: 1.66 KB

Versions: 6

Compression:

Stored size: 1.66 KB

Contents

require "metanorma/ietf/data/workgroups"
require "metanorma-utils"

module Metanorma
  module Ietf
    class Converter < ::Metanorma::Standoc::Converter
      def content_validate(doc)
        super
        image_validate(doc)
        workgroup_validate(doc)
        submission_validate(doc)
      end

      def ns(path)
        ::Metanorma::Utils::ns(path)
      end

      def submission_validate(doc)
        stream = doc.at(("//bibdata/series[@type = 'stream']/title"))&.text
        status = doc.at(("//bibdata/status/stage"))&.text
        stream == "editorial" && status != "informational" and
          @log.add("Document Attributes", nil,
                   "Editorial stream must have Informational status")
      end

      def image_validate(doc)
        doc.xpath("//image").each do |i|
          i["mimetype"] == "image/svg+xml" and next
          @log.add("MIME", i, "image #{i['src'][0, 40]} is not SVG!",
                   severity: 1)
        end
      end

      def workgroup_validate(doc)
        return if @workgroups.empty?

        doc.xpath("//bibdata/ext/editorialgroup/workgroup").each do |wg|
          wg_norm = wg.text.sub(/ (Working|Research) Group$/, "")
          @workgroups.include?(wg_norm) and next
          @log.add("Document Attributes", nil,
                   "IETF: unrecognised working group #{wg.text}",
                   severity: 1)
        end
      end

      def validate(doc)
        content_validate(doc)
        schema_validate(formattedstr_strip(doc.dup),
                        File.join(File.dirname(__FILE__), "ietf.rng"))
      end

      def cache_workgroup(_node)
        Metanorma::Ietf::Data::WORKGROUPS
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
metanorma-ietf-3.3.3 lib/metanorma/ietf/validate.rb
metanorma-ietf-3.3.2 lib/metanorma/ietf/validate.rb
metanorma-ietf-3.3.1 lib/metanorma/ietf/validate.rb
metanorma-ietf-3.3.0 lib/metanorma/ietf/validate.rb
metanorma-ietf-3.2.7 lib/metanorma/ietf/validate.rb
metanorma-ietf-3.2.6 lib/metanorma/ietf/validate.rb