Sha256: ee577918949aef9ce707a860e3e6c4d01872ecea40b78382b3bff20d167fb3db

Contents?: true

Size: 724 Bytes

Versions: 3

Compression:

Stored size: 724 Bytes

Contents

# frozen_string_literal: true

require 'proformaxml/helpers/export_helpers'

module ProformaXML
  class VersionAndNamespaceExtractor < ServiceBase
    def initialize(doc:)
      super()
      @doc = doc
    end

    def perform
      extract_schema_and_version
    end

    private

    def extract_schema_and_version
      namespace_regex = /^urn:proforma:v(\d.*)$/
      potential_namespaces = @doc.namespaces.filter do |_, href|
        href.match? namespace_regex
      end
      return unless potential_namespaces.length == 1

      {
        namespace: potential_namespaces.first[0].gsub('xmlns:', ''),
        version: namespace_regex.match(potential_namespaces.first[1])&.captures&.dig(0),
      }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
proformaxml-1.5.2 lib/proformaxml/services/version_and_namespace_extractor.rb
proformaxml-1.5.1 lib/proformaxml/services/version_and_namespace_extractor.rb
proformaxml-1.5.0 lib/proformaxml/services/version_and_namespace_extractor.rb