Class: XmlUtils::Node
- Inherits:
-
Object
- Object
- XmlUtils::Node
- Includes:
- Enumerable
- Defined in:
- lib/xmlutils/node.rb
Instance Attribute Summary collapse
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
- #deep_clone ⇒ Object
- #document ⇒ Object
- #each(&block) ⇒ Object
-
#initialize ⇒ Node
constructor
A new instance of Node.
- #next_sibling ⇒ Object
- #node_type ⇒ Object
- #previous_sibling ⇒ Object
- #remove ⇒ Object
- #root ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Node
Returns a new instance of Node.
42 43 44 |
# File 'lib/xmlutils/node.rb', line 42 def initialize @parent = nil end |
Instance Attribute Details
#parent ⇒ Object
Returns the value of attribute parent.
40 41 42 |
# File 'lib/xmlutils/node.rb', line 40 def parent @parent end |
Instance Method Details
#deep_clone ⇒ Object
90 91 92 |
# File 'lib/xmlutils/node.rb', line 90 def deep_clone Marshal.load(Marshal.dump(self)) end |
#document ⇒ Object
66 67 68 69 |
# File 'lib/xmlutils/node.rb', line 66 def document r = root r.is_a?(Document) ? r : nil end |
#each(&block) ⇒ Object
46 47 48 |
# File 'lib/xmlutils/node.rb', line 46 def each(&block) return to_enum unless block_given? end |
#next_sibling ⇒ Object
71 72 73 74 75 76 |
# File 'lib/xmlutils/node.rb', line 71 def next_sibling return nil unless @parent siblings = @parent.children idx = siblings.index(self) idx ? siblings[idx + 1] : nil end |
#node_type ⇒ Object
56 57 58 |
# File 'lib/xmlutils/node.rb', line 56 def node_type self.class.name.split('::').last.downcase.to_sym end |
#previous_sibling ⇒ Object
78 79 80 81 82 83 |
# File 'lib/xmlutils/node.rb', line 78 def previous_sibling return nil unless @parent siblings = @parent.children idx = siblings.index(self) idx && idx > 0 ? siblings[idx - 1] : nil end |
#remove ⇒ Object
85 86 87 88 |
# File 'lib/xmlutils/node.rb', line 85 def remove @parent.delete(self) if @parent self end |
#root ⇒ Object
60 61 62 63 64 |
# File 'lib/xmlutils/node.rb', line 60 def root node = self node = node.parent while node.parent node end |
#to_s ⇒ Object
50 51 52 53 54 |
# File 'lib/xmlutils/node.rb', line 50 def to_s output = "" write(output) output end |