Class: Lutaml::Xml::Location

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/xml/schema_location.rb

Overview

Location represents a single namespace-to-schema-location mapping Used within xsi:schemaLocation attribute values

Examples:

class MyNs < Lutaml::Xml::W3c::XmlNamespace
  uri "http://example.com/ns"
end

loc = Location.new(
  namespace_class: MyNs,
  location: "http://example.com/schema.xsd"
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(namespace_class:, location:) ⇒ Location

Returns a new instance of Location.

Parameters:

  • namespace_class (Class)

    An XmlNamespace subclass defining the namespace

  • location (String)

    The URL or path to the schema definition



22
23
24
25
26
27
28
29
30
31
# File 'lib/lutaml/xml/schema_location.rb', line 22

def initialize(namespace_class:, location:)
  unless namespace_class.is_a?(Class) && namespace_class < Lutaml::Xml::Namespace
    raise ArgumentError,
          "namespace_class must be an Xml::Namespace subclass, got #{namespace_class.class}. " \
          "String namespace URIs are no longer supported."
  end

  @namespace_class = namespace_class
  @location = location
end

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



18
19
20
# File 'lib/lutaml/xml/schema_location.rb', line 18

def location
  @location
end

#namespace_classObject (readonly)

Returns the value of attribute namespace_class.



18
19
20
# File 'lib/lutaml/xml/schema_location.rb', line 18

def namespace_class
  @namespace_class
end

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


45
46
47
48
49
# File 'lib/lutaml/xml/schema_location.rb', line 45

def eql?(other)
  other.class == self.class &&
    namespace_class == other.namespace_class &&
    location == other.location
end

#hashObject



52
53
54
# File 'lib/lutaml/xml/schema_location.rb', line 52

def hash
  [namespace_class, location].hash
end

#namespaceString

Returns the namespace URI from the XmlNamespace class

Returns:

  • (String)


35
36
37
# File 'lib/lutaml/xml/schema_location.rb', line 35

def namespace
  namespace_class.uri
end

#to_xml_attributeString

Format for xsi:schemaLocation attribute value (space-separated pair)

Returns:

  • (String)

    “namespace_uri schema_location”



41
42
43
# File 'lib/lutaml/xml/schema_location.rb', line 41

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