Class: Lutaml::Xml::Adapter::NamespaceData Private

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

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Simple data class for holding namespace URI and prefix pairs during XML parsing and serialization.

This is an internal class used by XML adapters. For defining custom namespaces, use Lutaml::Xml::Namespace instead.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri = nil, prefix = nil) ⇒ NamespaceData

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize instance

Parameters:

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

    the namespace URI

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

    the namespace prefix



28
29
30
31
# File 'lib/lutaml/xml/adapter/namespace_data.rb', line 28

def initialize(uri = nil, prefix = nil)
  @uri = uri
  @prefix = normalize_prefix(prefix)
end

Instance Attribute Details

#prefixString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return prefix

Returns:

  • (String)


22
23
24
# File 'lib/lutaml/xml/adapter/namespace_data.rb', line 22

def prefix
  @prefix
end

#uriString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return URI

Returns:

  • (String)


17
18
19
# File 'lib/lutaml/xml/adapter/namespace_data.rb', line 17

def uri
  @uri
end

Class Method Details

.to_keyString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Generate unique key for this namespace configuration

The key is based on prefix and URI, ensuring that same config = same key. This enables proper deduplication and lookup in hash structures.

Returns:

  • (String)

    unique key in format “prefix:uri” or “:uri” for default



39
40
41
42
43
44
45
46
47
48
# File 'lib/lutaml/xml/adapter/namespace_data.rb', line 39

def self.to_key
  prefix = prefix_default
  uri = self.uri

  if prefix && !prefix.empty?
    "#{prefix}:#{uri}"
  else
    ":#{uri}"
  end
end

Instance Method Details

#attr_nameObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



63
64
65
66
67
68
69
# File 'lib/lutaml/xml/adapter/namespace_data.rb', line 63

def attr_name
  if ::Lutaml::Model::Utils.present?(prefix)
    "xmlns:#{prefix}"
  else
    "xmlns"
  end
end

#normalize_prefix(prefix) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/lutaml/xml/adapter/namespace_data.rb', line 50

def normalize_prefix(prefix)
  # Only strip "xmlns:" prefix (e.g., "xmlns:foo" → "foo").
  # Do NOT strip "xmlns" from prefixes like "xmlns_1.0" (valid NCName).
  # Bare "xmlns" (no colon) represents the default namespace → return nil.
  prefix_str = prefix.to_s
  return nil if prefix_str == "xmlns"

  normalized_prefix = prefix_str.sub(/^xmlns:/, "")
  return if normalized_prefix.empty?

  normalized_prefix
end