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
##
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
##
def after datum last.after datum end
def at path, ns = document.root ? document.root.namespaces : {}
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
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
##
def before datum first.before datum end
def each(&block)
##
def each(&block) 0.upto(length - 1) do |x| yield self[x] end end
def empty?
##
def empty? length == 0 end
def first
##
def first self[0] end
def initialize document, list = []
def initialize document, list = [] @document = document list.each { |x| self << x } yield self if block_given? end
def inner_html
##
def inner_html collect{|j| j.inner_html}.join('') end
def inner_text
##
def inner_text collect{|j| j.inner_text}.join('') end
def last
##
def last self[length - 1] end
def remove_attr name
##
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
##
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
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)
##
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