lib/link_thumbnailer.rb in link_thumbnailer-0.0.6 vs lib/link_thumbnailer.rb in link_thumbnailer-1.0.0

- old
+ new

@@ -1,21 +1,24 @@ +require 'link_thumbnailer/engine' if defined? Rails require 'link_thumbnailer/config' require 'link_thumbnailer/object' require 'link_thumbnailer/fetcher' require 'link_thumbnailer/doc_parser' require 'link_thumbnailer/doc' require 'link_thumbnailer/img_url_filter' require 'link_thumbnailer/img_parser' require 'link_thumbnailer/img_comparator' require 'link_thumbnailer/web_image' - require 'link_thumbnailer/opengraph' - require 'link_thumbnailer/version' module LinkThumbnailer + module Rails + autoload :Routes, 'link_thumbnailer/rails/routes' + end + class << self attr_accessor :configuration, :object, :fetcher, :doc_parser, :img_url_filters, :img_parser @@ -28,10 +31,11 @@ %r{^http://ad\.doubleclick\.net/}, %r{^http://b\.scorecardresearch\.com/}, %r{^http://pixel\.quantserve\.com/}, %r{^http://s7\.addthis\.com/} ], + :rmagick_attributes => %w(source_url mime_type colums rows filesize number_colors), :limit => 10, :top => 5 ) end @@ -46,22 +50,23 @@ } self.object = LinkThumbnailer::Object.new self.fetcher = LinkThumbnailer::Fetcher.new self.doc_parser = LinkThumbnailer::DocParser.new + self.img_url_filters = [LinkThumbnailer::ImgUrlFilter.new] + self.img_parser = LinkThumbnailer::ImgParser.new(self.fetcher, self.img_url_filters) doc_string = self.fetcher.fetch(url) doc = self.doc_parser.parse(doc_string, url) self.object[:url] = doc.source_url # Try Opengraph first self.object = LinkThumbnailer::Opengraph.parse(self.object, doc) + return self.object if self.object.valid? # Else try manually - self.img_url_filters = [LinkThumbnailer::ImgUrlFilter.new] - self.img_parser = LinkThumbnailer::ImgParser.new(self.fetcher, self.img_url_filters) self.object[:title] = doc.title self.object[:description] = doc.description self.object[:images] = self.img_parser.parse(doc.img_abs_urls.dup)