Skip to content

Instantly share code, notes, and snippets.

@tenderlove
Created September 27, 2010 18:05
Show Gist options
  • Save tenderlove/599502 to your computer and use it in GitHub Desktop.
Save tenderlove/599502 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'nokogiri'
class MyFilter
def ends_with set, ends
set.map { |x| x.to_s }.join.end_with? ends
end
end
doc = Nokogiri.XML(DATA)
doc.xpath('//foo[ends_with(text(), "ar")]', MyFilter.new).each do |node|
puts node
end
__END__
<root>
<foo>bar</foo>
<foo>baz</foo>
</root>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment