Class: Lutaml::Xml::TypeNamespace::Declaration
- Inherits:
-
Object
- Object
- Lutaml::Xml::TypeNamespace::Declaration
- 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
-
#declared_at ⇒ Object
readonly
Returns the value of attribute declared_at.
-
#element_name ⇒ Object
readonly
Returns the value of attribute element_name.
-
#namespace_class ⇒ Object
readonly
Returns the value of attribute namespace_class.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
Instance Method Summary collapse
-
#initialize(namespace_class:, prefix:, declared_at:, element_name: nil) ⇒ Declaration
constructor
A new instance of Declaration.
-
#inline? ⇒ Boolean
Check if declared inline.
-
#parent_level? ⇒ Boolean
Check if declared at parent.
-
#root_level? ⇒ Boolean
Check if declared at root.
- #to_s ⇒ Object
-
#to_xmlns_attribute ⇒ String
Get the xmlns attribute string.
Constructor Details
#initialize(namespace_class:, prefix:, declared_at:, element_name: nil) ⇒ Declaration
Returns a new instance of Declaration.
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_at ⇒ Object (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_name ⇒ Object (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_class ⇒ Object (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 |
#prefix ⇒ Object (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
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
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
34 35 36 |
# File 'lib/lutaml/xml/type_namespace/declaration.rb', line 34 def root_level? @declared_at == :root end |
#to_s ⇒ Object
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_attribute ⇒ String
Get the xmlns attribute string
51 52 53 |
# File 'lib/lutaml/xml/type_namespace/declaration.rb', line 51 def to_xmlns_attribute "xmlns:#{@prefix}=#{@namespace_class.uri}" end |