Module: Manipulate
- Included in:
- Rind::Cdata, Rind::Comment, Rind::Element, Rind::ProcessingInstruction, Rind::Text
- Defined in:
- lib/rind/manipulate.rb
Overview
Note: These functions are not available for the root node in a tree.
Instance Method Summary collapse
-
#insert_after(*nodes) ⇒ Object
Calls Rind::Children::insert to add nodes after
self
. -
#insert_before(*nodes) ⇒ Object
Calls Rind::Children::insert to add nodes before
self
. -
#remove ⇒ Object
Calls Rind::Children::delete on
self
.
Instance Method Details
#insert_after(*nodes) ⇒ Object
Calls Rind::Children::insert to add nodes after self
.
Example
nodes = ['a', 'b', 'c']
nodes[0].insert_after('d', 'e') => ['a', 'd', 'e', 'b', 'c']
7 8 9 10 |
# File 'lib/rind/manipulate.rb', line 7 def insert_after(*nodes) children = self.parent.children children.insert(children.exact_index(self)+1, *nodes) end |
#insert_before(*nodes) ⇒ Object
Calls Rind::Children::insert to add nodes before self
.
Example
nodes = ['a', 'b', 'c']
nodes[2].insert_after('d', 'e') => ['a', 'b', 'd', 'e', 'c']
16 17 18 19 |
# File 'lib/rind/manipulate.rb', line 16 def insert_before(*nodes) children = self.parent.children children.insert(children.exact_index(self), *nodes) end |
#remove ⇒ Object
Calls Rind::Children::delete on self
.
Example
nodes = ['a', 'b', 'c']
nodes[1].delete => 'b'
25 26 27 |
# File 'lib/rind/manipulate.rb', line 25 def remove self.parent.children.delete(self) end |