class Nokogiri::XML::NodeSet

Nokogiri::XML::Node#css or Nokogiri::XML::Node#xpath
a NodeSet is return as a result of searching a Document via
A NodeSet contains a list of Nokogiri::XML::Node objects. Typically
###

def add_class name

Append the class attribute +name+ to all Node objects in the NodeSet.
##
def add_class name
  each do |el|
    next unless el.respond_to? :get_attribute
    classes = el.get_attribute('class').to_s.split(" ")
    el.set_attribute('class', classes.push(name).uniq.join(" "))
  end
  self
end

def after datum

Insert +datum+ after the last Node in this NodeSet
##
def after datum
  last.after datum
end

def at path, ns = document.root ? document.root.namespaces : {}

first Node. Otherwise, index in to the array with +path+.
If path is a string, search this document for +path+ returning the
##
def at path, ns = document.root ? document.root.namespaces : {}
  return self[path] if path.is_a?(Numeric)
  search(path, ns).first
end

def attr key, value = nil, &blk

on all Node objects in the NodeSet.
Set the attribute +key+ to +value+ or the return value of +blk+
##
def attr key, value = nil, &blk
  if value or blk
    each do |el|
      el.set_attribute(key, value || blk[el])
    end
    return self      
  end    
  if key.is_a? Hash
    key.each { |k,v| self.attr(k,v) }
    return self
  else
    return self[0].get_attribute(key)
  end
end

def before datum

Insert +datum+ before the first Node in this NodeSet
##
def before datum
  first.before datum
end

def each(&block)

Iterate over each node, yielding to +block+
##
def each(&block)
  0.upto(length - 1) do |x|
    yield self[x]
  end
end

def empty?

Is this NodeSet empty?
##
def empty?
  length == 0
end

def first

Get the first element of the NodeSet.
##
def first
  self[0]
end

def initialize document, list = []

Create a NodeSet with +document+ defaulting to +list+
def initialize document, list = []
  @document = document
  list.each { |x| self << x }
  yield self if block_given?
end

def inner_html

Get the inner html of all contained Node objects
##
def inner_html
  collect{|j| j.inner_html}.join('')
end

def inner_text

Get the inner text of all contained Node objects
##
def inner_text
  collect{|j| j.inner_text}.join('')
end

def last

Get the last element of the NodeSet.
##
def last
  self[length - 1]
end

def remove_attr name

Remove the attributed named +name+ from all Node objects in the NodeSet
##
def remove_attr name
  each do |el|
    next unless el.respond_to? :remove_attribute
    el.remove_attribute(name)
  end
  self      
end

def remove_class name = nil

Remove the class attribute +name+ from all Node objects in the NodeSet.
##
def remove_class name = nil
  each do |el|
    next unless el.respond_to? :get_attribute
    if name
      classes = el.get_attribute('class').to_s.split(" ")
      el.set_attribute('class', (classes - [name]).uniq.join(" "))
    else
      el.remove_attribute("class")
    end
  end
  self
end

def search *paths

Nokogiri::XML::Node#xpath
For more information see Nokogiri::XML::Node#css and

Search this document for +paths+
##
def search *paths
  ns = paths.last.is_a?(Hash) ? paths.pop : document.root.namespaces
  sub_set = NodeSet.new(document)
  document.decorate(sub_set)
  each do |node|
    node.search(*(paths + [ns])).each do |sub_node|
      sub_set << sub_node
    end
  end
  sub_set
end

def to_html *args

def to_html *args
  map { |x| x.to_html(*args) }.join('')
end

def to_s

def to_s
  map { |x| x.to_s }.join
end

def to_xhtml *args

def to_xhtml *args
  map { |x| x.to_xhtml(*args) }.join('')
end

def to_xml *args

def to_xml *args
  map { |x| x.to_xml(*args) }.join('')
end

def wrap(html, &blk)

Wrap this NodeSet with +html+ or the results of the builder in +blk+
##
def wrap(html, &blk)
  each do |j|
    new_parent = Nokogiri.make(html, &blk)
    j.parent.add_child(new_parent)
    new_parent.add_child(j)
  end
  self
end