Class: XML::MappingExtensions::Namespace

Inherits:
Object
  • Object
show all
Defined in:
lib/xml/mapping_extensions/namespace.rb

Overview

Encapsulates an XML namespace with a URI, schema location, and optional prefix.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri:, prefix: nil, schema_location: nil) ⇒ Namespace

Parameters:

  • uri (URI, String)

    the namespace URI

  • prefix (String, nil) (defaults to: nil)

    the namespace prefix

  • schema_location (String, nil) (defaults to: nil)

    the schema location

Raises:

  • (URI::InvalidURIError)

    if uri is nil, or a string that is not a valid URI

  • (URI::InvalidURIError)

    if schema_location is a string that is not a valid URI



24
25
26
27
28
29
# File 'lib/xml/mapping_extensions/namespace.rb', line 24

def initialize(uri:, prefix: nil, schema_location: nil)
  raise URI::InvalidURIError, 'uri cannot be nil' unless uri
  @uri             = MappingExtensions.to_uri_str(uri)
  @prefix          = prefix
  @schema_location = MappingExtensions.to_uri_str(schema_location)
end

Instance Attribute Details

#prefixString? (readonly)

Returns the namespace prefix.

Returns:

  • (String, nil)

    the namespace prefix



13
14
15
# File 'lib/xml/mapping_extensions/namespace.rb', line 13

def prefix
  @prefix
end

#schema_locationURI, ... (readonly)

Returns the schema location URI.

Returns:

  • (URI, String, nil)

    the schema location URI



16
17
18
# File 'lib/xml/mapping_extensions/namespace.rb', line 16

def schema_location
  @schema_location
end

#uriString (readonly)

Returns the string form of the namespace URI.

Returns:

  • (String)

    the string form of the namespace URI



10
11
12
# File 'lib/xml/mapping_extensions/namespace.rb', line 10

def uri
  @uri
end

Instance Method Details

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



35
36
37
# File 'lib/xml/mapping_extensions/namespace.rb', line 35

def ==(other)
  other.class == self.class && other.state == state
end

#hash



41
42
43
# File 'lib/xml/mapping_extensions/namespace.rb', line 41

def hash
  state.hash
end

#to_s



31
32
33
# File 'lib/xml/mapping_extensions/namespace.rb', line 31

def to_s
  "Namespace(uri: #{uri}, prefix: #{prefix || 'nil'}, schema_location: #{schema_location || 'nil'}"
end