Sha256: 2c039bca7d8a9b488b40d6d2644c516d433626c3f2b9f6486f566df121d20c21

Contents?: true

Size: 1.39 KB

Versions: 27

Compression:

Stored size: 1.39 KB

Contents

module Lutaml
  module Model
    class Location
      attr_reader :namespace, :location

      def initialize(namespace:, location:)
        @namespace = namespace
        @location = location
      end

      def to_xml_attribute
        "#{@namespace} #{@location}".strip
      end
    end

    class SchemaLocation
      DEFAULT_NAMESPACE = "http://www.w3.org/2001/XMLSchema-instance".freeze

      attr_reader :namespace, :prefix, :schema_location

      def initialize(schema_location:, prefix: "xsi",
namespace: DEFAULT_NAMESPACE)
        @original_schema_location = schema_location
        @schema_location = parsed_schema_locations(schema_location)
        @prefix = prefix
        @namespace = namespace
      end

      def to_xml_attributes
        {
          "xmlns:#{prefix}" => namespace,
          "#{prefix}:schemaLocation" => schema_location.map(&:to_xml_attribute).join(" "),
        }
      end

      def [](index)
        @schema_location[index]
      end

      def size
        @schema_location.size
      end

      private

      def parsed_schema_locations(schema_location)
        locations = if schema_location.is_a?(Hash)
                      schema_location
                    else
                      schema_location.split.each_slice(2)
                    end

        locations.map do |n, l|
          Location.new(namespace: n, location: l)
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
lutaml-model-0.5.4 lib/lutaml/model/schema_location.rb
lutaml-model-0.5.3 lib/lutaml/model/schema_location.rb
lutaml-model-0.5.2 lib/lutaml/model/schema_location.rb
lutaml-model-0.5.1 lib/lutaml/model/schema_location.rb
lutaml-model-0.5.0 lib/lutaml/model/schema_location.rb
lutaml-model-0.4.0 lib/lutaml/model/schema_location.rb
lutaml-model-0.3.30 lib/lutaml/model/schema_location.rb
lutaml-model-0.3.29 lib/lutaml/model/schema_location.rb
lutaml-model-0.3.28 lib/lutaml/model/schema_location.rb
lutaml-model-0.3.27 lib/lutaml/model/schema_location.rb
lutaml-model-0.3.26 lib/lutaml/model/schema_location.rb
lutaml-model-0.3.25 lib/lutaml/model/schema_location.rb
lutaml-model-0.3.24 lib/lutaml/model/schema_location.rb
lutaml-model-0.3.23 lib/lutaml/model/schema_location.rb
lutaml-model-0.3.22 lib/lutaml/model/schema_location.rb
lutaml-model-0.3.21 lib/lutaml/model/schema_location.rb
lutaml-model-0.3.20 lib/lutaml/model/schema_location.rb
lutaml-model-0.3.19 lib/lutaml/model/schema_location.rb
lutaml-model-0.3.18 lib/lutaml/model/schema_location.rb
lutaml-model-0.3.17 lib/lutaml/model/schema_location.rb