Class: Lutaml::Xml::XmlAttribute

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

Overview

Represents an XML attribute

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, value, namespace: nil, namespace_prefix: nil) ⇒ XmlAttribute

Returns a new instance of XmlAttribute.



9
10
11
12
13
14
# File 'lib/lutaml/xml/xml_attribute.rb', line 9

def initialize(name, value, namespace: nil, namespace_prefix: nil)
  @name = name
  @value = value
  @namespace = namespace
  @namespace_prefix = namespace_prefix
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/lutaml/xml/xml_attribute.rb', line 7

def name
  @name
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



7
8
9
# File 'lib/lutaml/xml/xml_attribute.rb', line 7

def namespace
  @namespace
end

#namespace_prefixObject (readonly)

Returns the value of attribute namespace_prefix.



7
8
9
# File 'lib/lutaml/xml/xml_attribute.rb', line 7

def namespace_prefix
  @namespace_prefix
end

#valueObject (readonly)

Returns the value of attribute value.



7
8
9
# File 'lib/lutaml/xml/xml_attribute.rb', line 7

def value
  @value
end

Instance Method Details

#namespaced_nameObject



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

def namespaced_name
  # For type-namespaced attributes (those with xml_namespace declaration),
  # return the prefixed name (e.g., "xml:lang", "ex:attr")
  # rather than URI:name format (e.g., "http://www.w3.org/XML/1998/namespace:lang")
  if namespace_prefix
    name
  elsif namespace
    "#{namespace}:#{unprefixed_name}"
  else
    unprefixed_name
  end
end

#unprefixed_nameObject



16
17
18
19
20
21
22
# File 'lib/lutaml/xml/xml_attribute.rb', line 16

def unprefixed_name
  if namespace_prefix
    name.split(":").last
  else
    name
  end
end