Class: Canon::Xml::Nodes::ElementNode
- Inherits:
-
Canon::Xml::Node
- Object
- Canon::Xml::Node
- Canon::Xml::Nodes::ElementNode
- Defined in:
- lib/canon/xml/nodes/element_node.rb
Overview
Element node in the XPath data model
Instance Attribute Summary collapse
-
#attribute_nodes ⇒ Object
readonly
Returns the value of attribute attribute_nodes.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#namespace_nodes ⇒ Object
readonly
Returns the value of attribute namespace_nodes.
-
#namespace_uri ⇒ Object
readonly
Returns the value of attribute namespace_uri.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
Attributes inherited from Canon::Xml::Node
Instance Method Summary collapse
- #add_attribute(attribute_node) ⇒ Object
- #add_namespace(namespace_node) ⇒ Object
-
#initialize(name:, namespace_uri: nil, prefix: nil) ⇒ ElementNode
constructor
A new instance of ElementNode.
- #node_info ⇒ Object
- #node_type ⇒ Object
- #qname ⇒ Object
-
#sorted_attribute_nodes ⇒ Object
Get attribute nodes in sorted order (by namespace URI then local name).
-
#sorted_namespace_nodes ⇒ Object
Get namespace nodes in sorted order (lexicographically by local name).
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_nodes ⇒ Object (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 |
#name ⇒ Object (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_nodes ⇒ Object (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_uri ⇒ Object (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 |
#prefix ⇒ Object (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_info ⇒ Object
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_type ⇒ Object
22 23 24 |
# File 'lib/canon/xml/nodes/element_node.rb', line 22 def node_type :element end |
#qname ⇒ Object
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_nodes ⇒ Object
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_nodes ⇒ Object
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 |