class Nokogiri::XML::Node
def css *rules
})
end
node_set.find_all { |node| node['some_attribute'] =~ /#{regex}/ }
def regex node_set, regex
node.css('title:regex("\w+")', Class.new {
For example:
matching NodeSet. Any other arguments are ones that you pass in.
want defined. The first argument to the method will be the current
classes, create a class and implement the custom pseudo class you
Custom CSS pseudo classes may also be defined. To define custom pseudo
node.css('div + p.green', 'div#one')
node.css('body h1.bold')
node.css('title')
selectors. For example:
Search this node for CSS +rules+. +rules+ must be one or more CSS
##
def css *rules # Pop off our custom function handler if it exists handler = ![ Hash, String, Symbol ].include?(rules.last.class) ? rules.pop : nil ns = rules.last.is_a?(Hash) ? rules.pop : document.root.namespaces rules = rules.map { |rule| CSS.xpath_for(rule, :prefix => ".//", :ns => ns) }.flatten.uniq + [ns, handler].compact xpath(*rules) end