Class: Lutaml::Xml::NamespaceDeclaration
- Inherits:
-
Object
- Object
- Lutaml::Xml::NamespaceDeclaration
- Defined in:
- lib/lutaml/xml/namespace_declaration.rb
Overview
Represents a single namespace declaration in an XML element
REFACTORED (Session 176): Stores DATA only, NO XML strings Accepts NamespaceDeclarationData in constructor Adapters build xmlns strings from this data
CRITICAL ARCHITECTURAL PRINCIPLE: This class stores WHAT and HOW (data decisions) Adapters build the actual xmlns=“uri” or xmlns:prefix=“uri” strings
Instance Attribute Summary collapse
-
#declared_at ⇒ Symbol
readonly
Where this declaration is made - :here - declared at this element - :inherited - inherited from parent - :local_on_use - should be declared locally when used.
-
#format ⇒ Symbol
readonly
Format of declaration (:default or :prefix).
-
#ns_object ⇒ Class
readonly
The XmlNamespace class for this declaration.
-
#prefix_override ⇒ String?
readonly
Custom prefix override from options.
-
#source ⇒ Symbol?
readonly
Source of this declaration (:input for parsed XML).
Instance Method Summary collapse
-
#attribute_form_default ⇒ Symbol
Get attribute_form_default setting.
-
#declared_here? ⇒ Boolean
Check if this declaration is made at this element.
-
#default_format? ⇒ Boolean
Check if this declaration uses default format.
-
#element_form_default ⇒ Symbol
Get element_form_default setting.
-
#from_input? ⇒ Boolean
Check if this declaration came from input XML.
-
#inherited? ⇒ Boolean
Check if this declaration is inherited from parent.
-
#initialize(data) ⇒ NamespaceDeclaration
constructor
Initialize from NamespaceDeclarationData.
-
#inspect ⇒ String
String representation for debugging.
-
#key ⇒ String
Get the namespace key for lookups.
-
#local_on_use? ⇒ Boolean
Check if this declaration should be made locally on use.
-
#merge(attrs) ⇒ NamespaceDeclaration
Create a copy with updated attributes.
-
#prefix ⇒ String?
Get the namespace prefix (if any).
-
#prefix_format? ⇒ Boolean
Check if this declaration uses prefix format.
-
#to_h ⇒ Hash
Convert to hash for debugging.
-
#uri ⇒ String
Get the namespace URI.
-
#xmlns_declaration ⇒ String
Backward compatibility: Build xmlns declaration string (Legacy API from pre-Session 176 refactoring).
Constructor Details
#initialize(data) ⇒ NamespaceDeclaration
Initialize from NamespaceDeclarationData
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/lutaml/xml/namespace_declaration.rb', line 54 def initialize(data) unless data.is_a?(NamespaceDeclarationData) raise ArgumentError, "Expected NamespaceDeclarationData, got #{data.class}" end @ns_object = data.namespace_class @format = data.format @declared_at = data.declared_at @source = data.source @prefix_override = data.prefix_override end |
Instance Attribute Details
#declared_at ⇒ Symbol (readonly)
Returns Where this declaration is made
-
:here - declared at this element
-
:inherited - inherited from parent
-
:local_on_use - should be declared locally when used.
43 44 45 |
# File 'lib/lutaml/xml/namespace_declaration.rb', line 43 def declared_at @declared_at end |
#format ⇒ Symbol (readonly)
Returns Format of declaration (:default or :prefix).
37 38 39 |
# File 'lib/lutaml/xml/namespace_declaration.rb', line 37 def format @format end |
#ns_object ⇒ Class (readonly)
Returns The XmlNamespace class for this declaration.
34 35 36 |
# File 'lib/lutaml/xml/namespace_declaration.rb', line 34 def ns_object @ns_object end |
#prefix_override ⇒ String? (readonly)
Returns Custom prefix override from options.
49 50 51 |
# File 'lib/lutaml/xml/namespace_declaration.rb', line 49 def prefix_override @prefix_override end |
#source ⇒ Symbol? (readonly)
Returns Source of this declaration (:input for parsed XML).
46 47 48 |
# File 'lib/lutaml/xml/namespace_declaration.rb', line 46 def source @source end |
Instance Method Details
#attribute_form_default ⇒ Symbol
Get attribute_form_default setting
144 145 146 147 148 149 150 |
# File 'lib/lutaml/xml/namespace_declaration.rb', line 144 def attribute_form_default if @ns_object.respond_to?(:attribute_form_default) @ns_object.attribute_form_default else :unqualified # W3C default end end |
#declared_here? ⇒ Boolean
Check if this declaration is made at this element
105 106 107 |
# File 'lib/lutaml/xml/namespace_declaration.rb', line 105 def declared_here? @declared_at == :here end |
#default_format? ⇒ Boolean
Check if this declaration uses default format
91 92 93 |
# File 'lib/lutaml/xml/namespace_declaration.rb', line 91 def default_format? @format == :default end |
#element_form_default ⇒ Symbol
Get element_form_default setting
133 134 135 136 137 138 139 |
# File 'lib/lutaml/xml/namespace_declaration.rb', line 133 def element_form_default if @ns_object.respond_to?(:element_form_default) @ns_object.element_form_default else :qualified # W3C default end end |
#from_input? ⇒ Boolean
Check if this declaration came from input XML
126 127 128 |
# File 'lib/lutaml/xml/namespace_declaration.rb', line 126 def from_input? @source == :input end |
#inherited? ⇒ Boolean
Check if this declaration is inherited from parent
112 113 114 |
# File 'lib/lutaml/xml/namespace_declaration.rb', line 112 def inherited? @declared_at == :inherited end |
#inspect ⇒ String
String representation for debugging
184 185 186 |
# File 'lib/lutaml/xml/namespace_declaration.rb', line 184 def inspect "#<NamespaceDeclaration #{@ns_object} format=#{@format} declared_at=#{@declared_at}>" end |
#key ⇒ String
Get the namespace key for lookups
70 71 72 |
# File 'lib/lutaml/xml/namespace_declaration.rb', line 70 def key @ns_object.to_key end |
#local_on_use? ⇒ Boolean
Check if this declaration should be made locally on use
119 120 121 |
# File 'lib/lutaml/xml/namespace_declaration.rb', line 119 def local_on_use? @declared_at == :local_on_use end |
#merge(attrs) ⇒ NamespaceDeclaration
Create a copy with updated attributes
156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/lutaml/xml/namespace_declaration.rb', line 156 def merge(attrs) # Create new NamespaceDeclarationData with merged attributes data = NamespaceDeclarationData.new( namespace_class: attrs[:ns_object] || @ns_object, format: attrs[:format] || @format, declared_at: attrs[:declared_at] || @declared_at, source: attrs.key?(:source) ? attrs[:source] : @source, prefix_override: attrs.key?(:prefix_override) ? attrs[:prefix_override] : @prefix_override, ) NamespaceDeclaration.new(data) end |
#prefix ⇒ String?
Get the namespace prefix (if any)
84 85 86 |
# File 'lib/lutaml/xml/namespace_declaration.rb', line 84 def prefix @prefix_override || @ns_object.prefix_default end |
#prefix_format? ⇒ Boolean
Check if this declaration uses prefix format
98 99 100 |
# File 'lib/lutaml/xml/namespace_declaration.rb', line 98 def prefix_format? @format == :prefix end |
#to_h ⇒ Hash
Convert to hash for debugging
171 172 173 174 175 176 177 178 179 |
# File 'lib/lutaml/xml/namespace_declaration.rb', line 171 def to_h { ns_object: @ns_object, format: @format, declared_at: @declared_at, source: @source, prefix_override: @prefix_override, }.compact end |
#uri ⇒ String
Get the namespace URI
77 78 79 |
# File 'lib/lutaml/xml/namespace_declaration.rb', line 77 def uri @ns_object.uri end |
#xmlns_declaration ⇒ String
Backward compatibility: Build xmlns declaration string (Legacy API from pre-Session 176 refactoring)
192 193 194 195 196 197 198 199 |
# File 'lib/lutaml/xml/namespace_declaration.rb', line 192 def xmlns_declaration if @format == :default "xmlns=\"#{uri}\"" else pfx = prefix "xmlns:#{pfx}=\"#{uri}\"" end end |