Class: Canon::Xml::Nodes::AttributeNode

Inherits:
Canon::Xml::Node show all
Defined in:
lib/canon/xml/nodes/attribute_node.rb

Overview

Attribute node in the XPath data model

Instance Attribute Summary collapse

Attributes inherited from Canon::Xml::Node

#children, #parent

Instance Method Summary collapse

Methods inherited from Canon::Xml::Node

#add_child, #in_node_set=, #in_node_set?

Constructor Details

#initialize(name:, value:, namespace_uri: nil, prefix: nil) ⇒ AttributeNode

Returns a new instance of AttributeNode.



12
13
14
15
16
17
18
# File 'lib/canon/xml/nodes/attribute_node.rb', line 12

def initialize(name:, value:, namespace_uri: nil, prefix: nil)
  super()
  @name = name
  @value = value
  @namespace_uri = namespace_uri
  @prefix = prefix
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/canon/xml/nodes/attribute_node.rb', line 10

def name
  @name
end

#namespace_uriObject (readonly)

Returns the value of attribute namespace_uri.



10
11
12
# File 'lib/canon/xml/nodes/attribute_node.rb', line 10

def namespace_uri
  @namespace_uri
end

#prefixObject (readonly)

Returns the value of attribute prefix.



10
11
12
# File 'lib/canon/xml/nodes/attribute_node.rb', line 10

def prefix
  @prefix
end

#valueObject (readonly)

Returns the value of attribute value.



10
11
12
# File 'lib/canon/xml/nodes/attribute_node.rb', line 10

def value
  @value
end

Instance Method Details

#local_nameObject



24
25
26
# File 'lib/canon/xml/nodes/attribute_node.rb', line 24

def local_name
  name
end

#node_infoObject



52
53
54
# File 'lib/canon/xml/nodes/attribute_node.rb', line 52

def node_info
  "name: #{name} value: #{value} namespace_uri: #{namespace_uri} prefix: #{prefix}"
end

#node_typeObject



20
21
22
# File 'lib/canon/xml/nodes/attribute_node.rb', line 20

def node_type
  :attribute
end

#qnameObject



28
29
30
# File 'lib/canon/xml/nodes/attribute_node.rb', line 28

def qname
  prefix.nil? || prefix.empty? ? name : "#{prefix}:#{name}"
end

#simple_inheritable?Boolean

Check if this is a simple inheritable attribute (xml:lang or xml:space)

Returns:

  • (Boolean)


38
39
40
# File 'lib/canon/xml/nodes/attribute_node.rb', line 38

def simple_inheritable?
  xml_attribute? && ["lang", "space"].include?(name)
end

#xml_attribute?Boolean

Check if this is an xml:* attribute

Returns:

  • (Boolean)


33
34
35
# File 'lib/canon/xml/nodes/attribute_node.rb', line 33

def xml_attribute?
  namespace_uri == "http://www.w3.org/XML/1998/namespace"
end

#xml_base?Boolean

Check if this is xml:base

Returns:

  • (Boolean)


48
49
50
# File 'lib/canon/xml/nodes/attribute_node.rb', line 48

def xml_base?
  xml_attribute? && name == "base"
end

#xml_id?Boolean

Check if this is xml:id

Returns:

  • (Boolean)


43
44
45
# File 'lib/canon/xml/nodes/attribute_node.rb', line 43

def xml_id?
  xml_attribute? && name == "id"
end