Sha256: ec5504c7cf5dc6f125e66230b1418847d36a4a556229df8deadb6304e792effa

Contents?: true

Size: 890 Bytes

Versions: 3

Compression:

Stored size: 890 Bytes

Contents

# frozen_striing_literal: true

module Lutaml
  module Model
    class XmlNamespace
      # Return name
      #
      # @return [String]
      #
      # @api private
      attr_accessor :uri

      # Return prefix
      #
      # @return [String]
      #
      # @api private
      attr_accessor :prefix

      # Initialize instance
      #
      # @param [String, nil] name
      # @param [String, nil] prefix
      #
      # @api private
      def initialize(uri = nil, prefix = nil)
        @uri = uri
        @prefix = normalize_prefix(prefix)
      end

      def normalize_prefix(prefix)
        normalized_prefix = prefix.to_s.gsub(/xmlns:?/, "")
        return if normalized_prefix.empty?

        normalized_prefix
      end

      def attr_name
        if prefix && !prefix.empty?
          "xmlns:#{prefix}"
        else
          "xmlns"
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
lutaml-model-0.3.1 lib/lutaml/model/xml_namespace.rb
lutaml-model-0.3.0 lib/lutaml/model/xml_namespace.rb
lutaml-model-0.2.1 lib/lutaml/model/xml_namespace.rb