Sha256: 9158670d73b659d8f4f0b0512e62c37faa6a79f61a5b66273defccfee9a9323f
Contents?: true
Size: 946 Bytes
Versions: 2
Compression:
Stored size: 946 Bytes
Contents
require 'RMagick' module LinkThumbnailer class ImgParser def initialize(fetcher, img_url_filter) @fetcher = fetcher @img_url_filters = [*img_url_filter] end def parse(img_urls) @img_url_filters.each do |filter| img_urls.delete_if { |i| filter.reject?(i) } end imgs = [] count = 0 img_urls.each { |i| break if count >= LinkThumbnailer.configuration.limit img = parse_one(i) next unless img img.extend LinkThumbnailer::ImgComparator imgs << img count += 1 } imgs.sort! unless imgs.count <= 1 imgs.first(LinkThumbnailer.configuration.top) end def parse_one(img_url) img_data = @fetcher.fetch(img_url) img = Magick::ImageList.new.from_blob(img_data).extend( LinkThumbnailer::WebImage ) img.source_url = img_url img rescue Exception nil end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
link_thumbnailer-1.0.5 | lib/link_thumbnailer/img_parser.rb |
link_thumbnailer-1.0.4 | lib/link_thumbnailer/img_parser.rb |