Class: Lutaml::Xml::XmlNamespace
- Inherits:
-
Object
- Object
- Lutaml::Xml::XmlNamespace
- Defined in:
- lib/lutaml/xml/xml_namespace.rb
Instance Attribute Summary collapse
-
#prefix ⇒ String
private
Return prefix.
-
#uri ⇒ String
private
Return name.
Class Method Summary collapse
-
.to_key ⇒ String
private
Generate unique key for this namespace configuration.
Instance Method Summary collapse
- #attr_name ⇒ Object
-
#initialize(uri = nil, prefix = nil) ⇒ XmlNamespace
constructor
private
Initialize instance.
- #normalize_prefix(prefix) ⇒ Object
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
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
#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
18 19 20 |
# File 'lib/lutaml/xml/xml_namespace.rb', line 18 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 name
11 12 13 |
# File 'lib/lutaml/xml/xml_namespace.rb', line 11 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/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_name ⇒ Object
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 |