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

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']


8
9
10
11
# File 'lib/rind/manipulate.rb', line 8

def insert_after(*nodes)
  children = self.parent.children
  children.insert(children.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']


18
19
20
21
# File 'lib/rind/manipulate.rb', line 18

def insert_before(*nodes)
  children = self.parent.children
  children.insert(children.index(self), *nodes)
end

#removeObject

Calls Rind::Children::delete on self.

Example

nodes = ['a', 'b', 'c']
nodes[1].delete => 'b'


28
29
30
# File 'lib/rind/manipulate.rb', line 28

def remove
  self.parent.children.delete(self)
end