You can do this with gsub string method and regular expresions
doc = open("myfile.html") { |f| f.read().gsub(/<img src="([^"]*)".*\/>/, '<%= image_tag("\1") %>') }
I don't have hpricot installed but it seems (check this hpricot-altering) that you coud use swap method on searched elements
imgs.each { |i| i.swap('<%= image_tag(' + i.src + ') %>') }
jcubic
2010-07-09 10:57:18