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?, #parse_errors, #parse_errors=, #text_content

Constructor Details

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

Returns a new instance of AttributeNode.



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

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.



8
9
10
# File 'lib/canon/xml/nodes/attribute_node.rb', line 8

def name
  @name
end

#namespace_uriObject (readonly)

Returns the value of attribute namespace_uri.



8
9
10
# File 'lib/canon/xml/nodes/attribute_node.rb', line 8

def namespace_uri
  @namespace_uri
end

#prefixObject (readonly)

Returns the value of attribute prefix.



8
9
10
# File 'lib/canon/xml/nodes/attribute_node.rb', line 8

def prefix
  @prefix
end

#valueObject (readonly)

Returns the value of attribute value.



8
9
10
# File 'lib/canon/xml/nodes/attribute_node.rb', line 8

def value
  @value
end

Instance Method Details

#local_nameObject



22
23
24
# File 'lib/canon/xml/nodes/attribute_node.rb', line 22

def local_name
  name
end

#node_infoObject



50
51
52
# File 'lib/canon/xml/nodes/attribute_node.rb', line 50

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

#node_typeObject



18
19
20
# File 'lib/canon/xml/nodes/attribute_node.rb', line 18

def node_type
  :attribute
end

#qnameObject



26
27
28
# File 'lib/canon/xml/nodes/attribute_node.rb', line 26

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)


36
37
38
# File 'lib/canon/xml/nodes/attribute_node.rb', line 36

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

#xml_attribute?Boolean

Check if this is an xml:* attribute

Returns:

  • (Boolean)


31
32
33
# File 'lib/canon/xml/nodes/attribute_node.rb', line 31

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

#xml_base?Boolean

Check if this is xml:base

Returns:

  • (Boolean)


46
47
48
# File 'lib/canon/xml/nodes/attribute_node.rb', line 46

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

#xml_id?Boolean

Check if this is xml:id

Returns:

  • (Boolean)


41
42
43
# File 'lib/canon/xml/nodes/attribute_node.rb', line 41

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