Class: Lutaml::Xml::NamespaceDeclarationData

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

Overview

Data for a namespace declaration NO XML construction - that’s the adapter’s job

This class maintains MECE responsibility: it only stores declaration data. XML string building belongs in adapters, NOT here.

CRITICAL ARCHITECTURAL PRINCIPLE: This class stores WHAT to declare and HOW to format it (data decisions). Adapters build the actual xmlns=“uri” or xmlns:prefix=“uri” strings.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(namespace_class:, format:, declared_at:, prefix_override: nil, source: nil) ⇒ NamespaceDeclarationData

Initialize namespace declaration data

Parameters:

  • namespace_class (Class)

    XmlNamespace class

  • format (Symbol)

    Format: :default or :prefix

  • declared_at (Symbol)

    Location: :here, :inherited, or :local_on_use

  • prefix_override (String, nil) (defaults to: nil)

    Custom prefix from options

  • source (Symbol, nil) (defaults to: nil)

    Source: :input if from parsed XML



24
25
26
27
28
29
30
31
32
# File 'lib/lutaml/xml/namespace_declaration_data.rb', line 24

def initialize(namespace_class:, format:, declared_at:,
             prefix_override: nil, source: nil)
  @namespace_class = namespace_class
  @format = format
  @declared_at = declared_at
  @prefix_override = prefix_override
  @source = source
  validate!
end

Instance Attribute Details

#declared_atObject (readonly)

Returns the value of attribute declared_at.



15
16
17
# File 'lib/lutaml/xml/namespace_declaration_data.rb', line 15

def declared_at
  @declared_at
end

#formatObject (readonly)

Returns the value of attribute format.



15
16
17
# File 'lib/lutaml/xml/namespace_declaration_data.rb', line 15

def format
  @format
end

#namespace_classObject (readonly)

Returns the value of attribute namespace_class.



15
16
17
# File 'lib/lutaml/xml/namespace_declaration_data.rb', line 15

def namespace_class
  @namespace_class
end

#prefix_overrideObject (readonly)

Returns the value of attribute prefix_override.



15
16
17
# File 'lib/lutaml/xml/namespace_declaration_data.rb', line 15

def prefix_override
  @prefix_override
end

#sourceObject (readonly)

Returns the value of attribute source.



15
16
17
# File 'lib/lutaml/xml/namespace_declaration_data.rb', line 15

def source
  @source
end

Instance Method Details

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

Equality check

Parameters:

Returns:

  • (Boolean)


123
124
125
126
127
128
129
130
# File 'lib/lutaml/xml/namespace_declaration_data.rb', line 123

def ==(other)
  other.is_a?(NamespaceDeclarationData) &&
    other.namespace_class == @namespace_class &&
    other.format == @format &&
    other.declared_at == @declared_at &&
    other.prefix_override == @prefix_override &&
    other.source == @source
end

#attribute_form_defaultSymbol

Get attribute_form_default setting

Returns:

  • (Symbol)

    :qualified or :unqualified



106
107
108
109
110
111
112
# File 'lib/lutaml/xml/namespace_declaration_data.rb', line 106

def attribute_form_default
  if @namespace_class.respond_to?(:attribute_form_default)
    @namespace_class.attribute_form_default
  else
    :unqualified # W3C default
  end
end

#declared_here?Boolean

Check if declared at this location

Returns:

  • (Boolean)


48
49
50
# File 'lib/lutaml/xml/namespace_declaration_data.rb', line 48

def declared_here?
  @declared_at == :here
end

#default_format?Boolean

Check if default format

Returns:

  • (Boolean)


42
43
44
# File 'lib/lutaml/xml/namespace_declaration_data.rb', line 42

def default_format?
  @format == :default
end

#element_form_defaultSymbol

Get element_form_default setting

Returns:

  • (Symbol)

    :qualified or :unqualified



96
97
98
99
100
101
102
# File 'lib/lutaml/xml/namespace_declaration_data.rb', line 96

def element_form_default
  if @namespace_class.respond_to?(:element_form_default)
    @namespace_class.element_form_default
  else
    :qualified # W3C default
  end
end

#from_input?Boolean

Check if from parsed input

Returns:

  • (Boolean)


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

def from_input?
  @source == :input
end

#has_prefix?Boolean

Check if namespace has a prefix defined

Returns:

  • (Boolean)


90
91
92
# File 'lib/lutaml/xml/namespace_declaration_data.rb', line 90

def has_prefix?
  !prefix.nil?
end

#hashInteger

Hash code for use in sets/hashes

Returns:

  • (Integer)


136
137
138
139
# File 'lib/lutaml/xml/namespace_declaration_data.rb', line 136

def hash
  [@namespace_class, @format, @declared_at, @prefix_override,
   @source].hash
end

#inherited?Boolean

Check if inherited from parent

Returns:

  • (Boolean)


54
55
56
# File 'lib/lutaml/xml/namespace_declaration_data.rb', line 54

def inherited?
  @declared_at == :inherited
end

#inspectString

String representation for debugging

Returns:

  • (String)


116
117
118
# File 'lib/lutaml/xml/namespace_declaration_data.rb', line 116

def inspect
  "#<NamespaceDeclarationData #{@namespace_class} format=#{@format} declared_at=#{@declared_at}>"
end

#keyString

Get namespace key for lookups

Returns:

  • (String)


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

def key
  @namespace_class.to_key
end

#local_on_use?Boolean

Check if local on use

Returns:

  • (Boolean)


60
61
62
# File 'lib/lutaml/xml/namespace_declaration_data.rb', line 60

def local_on_use?
  @declared_at == :local_on_use
end

#prefixString?

Get effective prefix (override or default)

Returns:

  • (String, nil)


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

def prefix
  @prefix_override || @namespace_class.prefix_default
end

#prefix_format?Boolean

Check if prefix format

Returns:

  • (Boolean)


36
37
38
# File 'lib/lutaml/xml/namespace_declaration_data.rb', line 36

def prefix_format?
  @format == :prefix
end

#uriString

Get namespace URI

Returns:

  • (String)


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

def uri
  @namespace_class.uri
end