Class: Lutaml::Xml::TypeNamespace::Declaration

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

Overview

Value object representing a type namespace declaration

Type namespaces are declared on PARENT elements and used by CHILD elements as prefixes.

Constant Summary collapse

VALID_DECLARED_AT_VALUES =
%i[root parent inline].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(namespace_class:, prefix:, declared_at:, element_name: nil) ⇒ Declaration

Returns a new instance of Declaration.

Parameters:

  • namespace_class (XmlNamespace)

    The namespace class

  • prefix (String)

    The prefix to use

  • declared_at (Symbol)

    :root, :parent, or :inline

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

    The element name (for debugging)



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/lutaml/xml/type_namespace/declaration.rb', line 19

def initialize(namespace_class:, prefix:, declared_at:,
    element_name: nil)
  unless VALID_DECLARED_AT_VALUES.include?(declared_at)
    raise ArgumentError,
          "declared_at must be :root, :parent, or :inline, got: #{declared_at.inspect}"
  end

  @namespace_class = namespace_class
  @prefix = prefix
  @declared_at = declared_at
  @element_name = element_name
  freeze
end

Instance Attribute Details

#declared_atObject (readonly)

Returns the value of attribute declared_at.



13
14
15
# File 'lib/lutaml/xml/type_namespace/declaration.rb', line 13

def declared_at
  @declared_at
end

#element_nameObject (readonly)

Returns the value of attribute element_name.



13
14
15
# File 'lib/lutaml/xml/type_namespace/declaration.rb', line 13

def element_name
  @element_name
end

#namespace_classObject (readonly)

Returns the value of attribute namespace_class.



13
14
15
# File 'lib/lutaml/xml/type_namespace/declaration.rb', line 13

def namespace_class
  @namespace_class
end

#prefixObject (readonly)

Returns the value of attribute prefix.



13
14
15
# File 'lib/lutaml/xml/type_namespace/declaration.rb', line 13

def prefix
  @prefix
end

Instance Method Details

#inline?Boolean

Check if declared inline

Returns:

  • (Boolean)


44
45
46
# File 'lib/lutaml/xml/type_namespace/declaration.rb', line 44

def inline?
  @declared_at == :inline
end

#parent_level?Boolean

Check if declared at parent

Returns:

  • (Boolean)


39
40
41
# File 'lib/lutaml/xml/type_namespace/declaration.rb', line 39

def parent_level?
  @declared_at == :parent
end

#root_level?Boolean

Check if declared at root

Returns:

  • (Boolean)


34
35
36
# File 'lib/lutaml/xml/type_namespace/declaration.rb', line 34

def root_level?
  @declared_at == :root
end

#to_sObject



55
56
57
# File 'lib/lutaml/xml/type_namespace/declaration.rb', line 55

def to_s
  "TypeNamespaceDeclaration: #{@prefix}=#{@namespace_class.uri} (#{@declared_at})"
end

#to_xmlns_attributeString

Get the xmlns attribute string

Returns:

  • (String)

    The xmlns declaration (e.g., “xmlns:dc=…”)



51
52
53
# File 'lib/lutaml/xml/type_namespace/declaration.rb', line 51

def to_xmlns_attribute
  "xmlns:#{@prefix}=#{@namespace_class.uri}"
end