Class: Lutaml::Xml::DeclarationPlan::AttributeNode

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

Overview

AttributeNode represents the namespace prefix decision for a single XML attribute

This is a PURE DATA structure - it stores the W3C-compliant prefix decision made by DeclarationPlanner but contains NO decision-making logic itself.

The key field is ‘use_prefix`:

  • nil => attribute has NO prefix (W3C :unqualified or blank namespace)

  • String => attribute uses this specific prefix

Examples:

Same namespace, unqualified (NO prefix)

# Element in ParentNs, attribute in ParentNs, attributeFormDefault: :unqualified
attr_node = AttributeNode.new(
  local_name: "parent_ns_attr",
  use_prefix: nil,  # NO prefix (W3C compliant)
  namespace_uri: "http://example.com/parent"
)
attr_node.qualified_name  # => "parent_ns_attr" (no prefix)

Different namespace (WITH prefix)

# Element in ParentNs, attribute in ChildNs
attr_node = AttributeNode.new(
  local_name: "child_attr",
  use_prefix: "child",  # YES prefix
  namespace_uri: "http://example.com/child"
)
attr_node.qualified_name  # => "child:child_attr"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(local_name:, use_prefix:, namespace_uri: nil) ⇒ AttributeNode

Initialize an attribute node

Parameters:

  • local_name (String)

    Attribute name without prefix

  • use_prefix (String, nil)

    Prefix for attribute (nil = no prefix)

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

    Namespace URI



50
51
52
53
54
# File 'lib/lutaml/xml/declaration_plan/attribute_node.rb', line 50

def initialize(local_name:, use_prefix:, namespace_uri: nil)
  @local_name = local_name
  @use_prefix = use_prefix
  @namespace_uri = namespace_uri
end

Instance Attribute Details

#local_nameString (readonly)

Returns Attribute local name (without prefix).

Returns:

  • (String)

    Attribute local name (without prefix)



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

def local_name
  @local_name
end

#namespace_uriString? (readonly)

Returns Namespace URI for this attribute.

Returns:

  • (String, nil)

    Namespace URI for this attribute



43
44
45
# File 'lib/lutaml/xml/declaration_plan/attribute_node.rb', line 43

def namespace_uri
  @namespace_uri
end

#use_prefixString? (readonly)

Returns Prefix to use for this attribute nil = no prefix (W3C :unqualified or blank namespace) String = use this prefix.

Returns:

  • (String, nil)

    Prefix to use for this attribute nil = no prefix (W3C :unqualified or blank namespace) String = use this prefix



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

def use_prefix
  @use_prefix
end

Instance Method Details

#prefixed?Boolean

Check if attribute has a prefix

Returns:

  • (Boolean)

    true if prefix present



68
69
70
# File 'lib/lutaml/xml/declaration_plan/attribute_node.rb', line 68

def prefixed?
  !use_prefix.nil?
end

#qualified_nameString

Get the qualified attribute name (with prefix if applicable)

This is what adapters should use when creating XML attributes.

Returns:

  • (String)

    Qualified name: “prefix:name” or “name”



61
62
63
# File 'lib/lutaml/xml/declaration_plan/attribute_node.rb', line 61

def qualified_name
  use_prefix ? "#{use_prefix}:#{local_name}" : local_name
end

#unqualified?Boolean

Check if attribute is unqualified (no prefix)

Returns:

  • (Boolean)

    true if no prefix



75
76
77
# File 'lib/lutaml/xml/declaration_plan/attribute_node.rb', line 75

def unqualified?
  use_prefix.nil?
end