Ability to replace a node with another node or string

```
element = Oga::XML::Element.new(:name => 'div')
some_node.replace(element)
```

You can also pass a `String` to  `replace` and it will be replaced with
a `Oga::XML::Text` node

```
some_node.replace('this will replace the current node with a text node')
```

closes #115
This commit is contained in:
Tero Tasanen committed 2015-06-17 21:27:50 +03:00
1 parent fe7e2e4f74
commit 0b4791b277
2 files changed
+43

No files matched your search

+21
View File
@@ -152,6 +152,27 @@ module Oga
return node_set.delete(self) if node_set
end
##
# Replaces the current node with another.
#
# @example Replacing with an element
# element = Oga::XML::Element.new(:name => 'div')
# some_node.replace(element)
#
# @example Replacing with a String
# some_node.replace('this will replace the current node with a text node')
#
# @param [String|Oga::XML::Node] other
#
def replace(other)
if other.is_a?(String)
other = Text.new(:text => other)
end
before(other)
remove
end
##
# Inserts the given node before the current node.
#