Class: Lutaml::Xml::ParsedNamespaceDeclaration

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

Overview

Represents a single namespace declaration extracted from parsed XML.

This is the core OOP representation of a parsed namespace declaration. Namespace URIs are treated as opaque strings — the model layer makes no assumptions about their format (http://, urn:, or plain strings).

Examples:

decl = ParsedNamespaceDeclaration.new(
  uri: "http://example.com/ns",
  prefix: "ex",
  format: :prefix,
  declared_at_path: []
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri:, prefix: nil, format: :default, declared_at_path: [], canonical_uri: nil, original_uri: nil) ⇒ ParsedNamespaceDeclaration

Returns a new instance of ParsedNamespaceDeclaration.



47
48
49
50
51
52
53
54
55
56
# File 'lib/lutaml/xml/parsed_namespace_declaration.rb', line 47

def initialize(uri:, prefix: nil, format: :default, declared_at_path: [],
             canonical_uri: nil, original_uri: nil)
  @uri = uri
  @prefix = prefix
  @format = format
  @declared_at_path = declared_at_path
  @canonical_uri = canonical_uri
  @original_uri = original_uri
  validate!
end

Instance Attribute Details

#canonical_uriString? (readonly)

Canonical URI — set when this is an alias declaration (the model-level canonical namespace URI)

Returns:

  • (String, nil)


40
41
42
# File 'lib/lutaml/xml/parsed_namespace_declaration.rb', line 40

def canonical_uri
  @canonical_uri
end

#declared_at_pathArray<String> (readonly)

Array of element path segments where this was declared

root, [“child”] = child element, etc.

Returns:

  • (Array<String>)


35
36
37
# File 'lib/lutaml/xml/parsed_namespace_declaration.rb', line 35

def declared_at_path
  @declared_at_path
end

#formatSymbol (readonly)

:default or :prefix

Returns:

  • (Symbol)


30
31
32
# File 'lib/lutaml/xml/parsed_namespace_declaration.rb', line 30

def format
  @format
end

#original_uriString? (readonly)

Original URI from input — set when this is an alias declaration (the actual URI that appeared in the input XML)

Returns:

  • (String, nil)


45
46
47
# File 'lib/lutaml/xml/parsed_namespace_declaration.rb', line 45

def original_uri
  @original_uri
end

#prefixString? (readonly)

nil for default namespace, String for prefixed

Returns:

  • (String, nil)


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

def prefix
  @prefix
end

#uriString (readonly)

URI is an opaque string - no format assumptions

Returns:

  • (String)


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

def uri
  @uri
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eql?

Equality based on all fields

Parameters:

  • other (Object)

Returns:

  • (Boolean)


92
93
94
95
96
97
98
99
100
# File 'lib/lutaml/xml/parsed_namespace_declaration.rb', line 92

def ==(other)
  other.is_a?(ParsedNamespaceDeclaration) &&
    other.uri == @uri &&
    other.prefix == @prefix &&
    other.format == @format &&
    other.declared_at_path == @declared_at_path &&
    other.canonical_uri == @canonical_uri &&
    other.original_uri == @original_uri
end

#alias?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/lutaml/xml/parsed_namespace_declaration.rb', line 66

def alias?
  !@canonical_uri.nil?
end

#default_namespace?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/lutaml/xml/parsed_namespace_declaration.rb', line 58

def default_namespace?
  @format == :default
end

#effective_uriString

The effective URI for model resolution (canonical for aliases)

Returns:

  • (String)


72
73
74
# File 'lib/lutaml/xml/parsed_namespace_declaration.rb', line 72

def effective_uri
  @canonical_uri || @uri
end

#hashInteger

Returns:

  • (Integer)


105
106
107
108
# File 'lib/lutaml/xml/parsed_namespace_declaration.rb', line 105

def hash
  [@uri, @prefix, @format, @declared_at_path, @canonical_uri,
   @original_uri].hash
end

#inspectString

Returns:

  • (String)


111
112
113
114
# File 'lib/lutaml/xml/parsed_namespace_declaration.rb', line 111

def inspect
  "#<ParsedNamespaceDecl prefix=#{@prefix.inspect} uri=#{@uri.inspect} " \
    "at=#{@declared_at_path.inspect}>"
end

#keyString

Unique key for hash/set operations: prefix + effective_uri

Returns:

  • (String)


84
85
86
87
# File 'lib/lutaml/xml/parsed_namespace_declaration.rb', line 84

def key
  prefix_str = @prefix ? "#{@prefix}:" : ""
  "#{prefix_str}#{effective_uri}"
end

#prefixed_namespace?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/lutaml/xml/parsed_namespace_declaration.rb', line 62

def prefixed_namespace?
  @format == :prefix
end

#serialization_uriString

The URI to emit in serialization (original for aliases, canonical otherwise)

Returns:

  • (String)


78
79
80
# File 'lib/lutaml/xml/parsed_namespace_declaration.rb', line 78

def serialization_uri
  @original_uri || @canonical_uri || @uri
end