Skip to content

Instantly share code, notes, and snippets.

@leopku
Forked from tenderlove/foo.rb
Created January 27, 2014 15:14
Show Gist options
  • Save leopku/8650148 to your computer and use it in GitHub Desktop.
Save leopku/8650148 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