Class: Lutaml::Xml::XmlNamespace

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

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:

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


26
27
28
29
# File 'lib/lutaml/xml/xml_namespace.rb', line 26

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)


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

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 name

Returns:

  • (String)


11
12
13
# File 'lib/lutaml/xml/xml_namespace.rb', line 11

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/xml_namespace.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



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

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

#normalize_prefix(prefix) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/lutaml/xml/xml_namespace.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