Class: Lutaml::Xml::Adapter::NamespaceData Private
- Inherits:
-
Object
- Object
- Lutaml::Xml::Adapter::NamespaceData
- 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
-
#prefix ⇒ String
private
Return prefix.
-
#uri ⇒ String
private
Return URI.
Class Method Summary collapse
-
.to_key ⇒ String
private
Generate unique key for this namespace configuration.
Instance Method Summary collapse
- #attr_name ⇒ Object private
-
#initialize(uri = nil, prefix = nil) ⇒ NamespaceData
constructor
private
Initialize instance.
- #normalize_prefix(prefix) ⇒ Object private
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
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
#prefix ⇒ String
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
22 23 24 |
# File 'lib/lutaml/xml/adapter/namespace_data.rb', line 22 def prefix @prefix end |
#uri ⇒ String
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
17 18 19 |
# File 'lib/lutaml/xml/adapter/namespace_data.rb', line 17 def uri @uri end |
Class Method Details
.to_key ⇒ String
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.
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_name ⇒ 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.
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 |