Class: Shale::Adapter::REXML::Node Private
- Inherits:
-
Object
- Object
- Shale::Adapter::REXML::Node
- Defined in:
- lib/shale/adapter/rexml/node.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Wrapper around REXML::Element API
Instance Method Summary collapse
-
#attributes ⇒ Hash
private
Return all attributes associated with the node.
-
#children ⇒ Array<Shale::Adapter::REXML::Node>
private
Return node’s element children.
-
#initialize(node) ⇒ Node
constructor
private
Initialize object with REXML element.
-
#name ⇒ String
private
Return name of the node in the format of namespace:name when the node is namespaced or just name when it’s not.
-
#namespaces ⇒ Hash<String, String>
private
Return namespaces defined on document.
-
#parent ⇒ Shale::Adapter::REXML::Node?
private
Return node’s parent.
-
#text ⇒ String
private
Return first text child of a node.
Constructor Details
#initialize(node) ⇒ Node
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize object with REXML element
17 18 19 |
# File 'lib/shale/adapter/rexml/node.rb', line 17 def initialize(node) @node = node end |
Instance Method Details
#attributes ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return all attributes associated with the node
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/shale/adapter/rexml/node.rb', line 54 def attributes attributes = @node.attributes.values.map do |attribute| attribute.is_a?(Hash) ? attribute.values : attribute end.flatten attributes.each_with_object({}) do |attribute, hash| name = [Utils.presence(attribute.namespace), attribute.name].compact.join(':') hash[name] = attribute.value end end |
#children ⇒ Array<Shale::Adapter::REXML::Node>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return node’s element children
81 82 83 84 85 86 |
# File 'lib/shale/adapter/rexml/node.rb', line 81 def children @node .children .filter { |e| e.node_type == :element } .map { |e| self.class.new(e) } end |
#name ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return name of the node in the format of namespace:name when the node is namespaced or just name when it’s not
45 46 47 |
# File 'lib/shale/adapter/rexml/node.rb', line 45 def name [Utils.presence(@node.namespace), @node.name].compact.join(':') end |
#namespaces ⇒ Hash<String, String>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return namespaces defined on document
29 30 31 |
# File 'lib/shale/adapter/rexml/node.rb', line 29 def namespaces @node.namespaces end |
#parent ⇒ Shale::Adapter::REXML::Node?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return node’s parent
70 71 72 73 74 |
# File 'lib/shale/adapter/rexml/node.rb', line 70 def parent if @node.parent && @node.parent.name != '' self.class.new(@node.parent) end end |
#text ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return first text child of a node
93 94 95 |
# File 'lib/shale/adapter/rexml/node.rb', line 93 def text @node.text end |