module Ayril::XMLNode::NodeManipulation
Public Instance Methods
clean_whitespace()
click to toggle source
Clean the whitespace of the node, i.e. remove all of its children text nodes that contain only whitespace.
# File lib/ayril/xml_node/node_manipulation.rb, line 54 def clean_whitespace node = self.childAtIndex 0 while node next_node = node.nextSibling node.remove if node.kind == NSXMLTextKind and node.stringValue =~ /\S/ node = next_node end self end
inner_html()
click to toggle source
# File lib/ayril/xml_node/node_manipulation.rb, line 70 def inner_html; self.children.invoke(:XMLString).join end
remove()
click to toggle source
Removes node from parent and return the removed node itself.
# File lib/ayril/xml_node/node_manipulation.rb, line 25 def remove self.tap { |e| e.parent.removeChildAtIndex e.index } end
replace(content)
click to toggle source
Replaces a node with another node and returns the old node.
# File lib/ayril/xml_node/node_manipulation.rb, line 45 def replace(content) content = content.to_elem if content.respond_to? :to_elem self.parent.replaceChildAtIndex self.index, withNode: content self end
Also aliased as: swap
update(content='')
click to toggle source
Updates the content of node. If passed nothing or a blank string, the children are cleared. If passed a string, the string is parsed into element(s). Passing an element or an array of elements is good. All elements are first detached if possible.
# File lib/ayril/xml_node/node_manipulation.rb, line 33 def update(content='') if content == ''; children = nil elsif content.respond_to? :to_s children = XMLElement.alloc.initWithXMLString("<r>#{content}</r>", error: nil).children elsif content.kind_of? XMLElement; children = [content] end children.each { |child| child.detach } if not children.nil? self.setChildren children end