iterationlabs/ruby-readability — pull request #38 by louismullie (2012-12-14 04:45:05+00:00)
Title: JRuby compatibility: use FastImage instead of MiniMagick for image retrieval.

Hello,

This gem is extremely useful, but the image retrieval feature does not work in JRuby. This is because it uses `mini_magick`, which relies on C extensions. I have made a few modifications to the code to use the [fastimage](https://github.com/sdsykes/fastimage) gem instead of `mini_magick` to get the size of remote images. Performance is essentially equivalent between the two options, with `fastimage` being a tad bit slower.

```
require 'open-uri'
require 'benchmark'

urls = [
"http://www.cbc.ca/news/canada/montreal/story/2011/07/05/quebec-turcotte-verdict.html",
"http://www.cbc.ca/news/politics/story/2012/12/13/pol-cp-scoc-terror-khawaja.html",
"http://www.cbc.ca/news/world/story/2012/12/13/bieber-plot.html",
"http://www.cbc.ca/news/canada/ottawa/story/2012/12/13/ottawa-your-city-deals-lcbo-cards.html",
"http://www.cbc.ca/news/canada/story/2012/12/13/detention-children-canada.html",
"http://www.cbc.ca/news/canada/montreal/story/2012/12/13/quebec-doctor-guy-turcotte-release.html",
"http://www.cbc.ca/news/arts/story/2012/12/12/golden-globe-nominees-film-tv.html"
]

urls.map! { |url| open(url) }

images = []

require 'ruby-readability'

Benchmark.bm do |x|
x.report do
1000.times do
urls.each do |body|
doc = Readability::Document.new(body, :tags => %w[div p img a])
images << doc.images
end
end
end
end

# user system total real
# 8.590000 0.040000 8.630000 ( 8.646033)

require 'ruby-readability2'

Benchmark.bm do |x|
x.report do
1000.times do
urls.each do |body|
doc = Readability2::Document.new(body, :tags => %w[div p img a])
images << doc.images
end
end
end
end

# user system total real
# 8.650000 0.040000 8.690000 ( 8.743825)
```

Let me know if you are interested in merging this. Otherwise, I might just push it as `ruby-readability-jruby` or something along those lines.