Class: Canon::Xml::Nodes::ElementNode

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

Overview

Element 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:, namespace_uri: nil, prefix: nil) ⇒ ElementNode

Returns a new instance of ElementNode.



13
14
15
16
17
18
19
20
# File 'lib/canon/xml/nodes/element_node.rb', line 13

def initialize(name:, namespace_uri: nil, prefix: nil)
  super()
  @name = name
  @namespace_uri = namespace_uri
  @prefix = prefix
  @namespace_nodes = []
  @attribute_nodes = []
end

Instance Attribute Details

#attribute_nodesObject (readonly)

Returns the value of attribute attribute_nodes.



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

def attribute_nodes
  @attribute_nodes
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#namespace_nodesObject (readonly)

Returns the value of attribute namespace_nodes.



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

def namespace_nodes
  @namespace_nodes
end

#namespace_uriObject (readonly)

Returns the value of attribute namespace_uri.



10
11
12
# File 'lib/canon/xml/nodes/element_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/element_node.rb', line 10

def prefix
  @prefix
end

Instance Method Details

#add_attribute(attribute_node) ⇒ Object



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

def add_attribute(attribute_node)
  attribute_node.parent = self
  @attribute_nodes << attribute_node
end

#add_namespace(namespace_node) ⇒ Object



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

def add_namespace(namespace_node)
  namespace_node.parent = self
  @namespace_nodes << namespace_node
end

#node_infoObject



54
55
56
# File 'lib/canon/xml/nodes/element_node.rb', line 54

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

#node_typeObject



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

def node_type
  :element
end

#qnameObject



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

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

#sorted_attribute_nodesObject

Get attribute nodes in sorted order (by namespace URI then local name)



48
49
50
51
52
# File 'lib/canon/xml/nodes/element_node.rb', line 48

def sorted_attribute_nodes
  @attribute_nodes.sort_by do |attr|
    [attr.namespace_uri.to_s, attr.local_name]
  end
end

#sorted_namespace_nodesObject

Get namespace nodes in sorted order (lexicographically by local name)



41
42
43
44
45
# File 'lib/canon/xml/nodes/element_node.rb', line 41

def sorted_namespace_nodes
  @namespace_nodes.sort_by do |ns|
    ns.local_name.to_s
  end
end