Sha256: 4bf42418c298dbb5fc04dba015dc7acdfa850845d529cb02df4a6d651908fff3

Contents?: true

Size: 698 Bytes

Versions: 20

Compression:

Stored size: 698 Bytes

Contents

require 'link_thumbnailer/scrapers/default/base'
require 'link_thumbnailer/models/favicon'

module LinkThumbnailer
  module Scrapers
    module Default
      class Favicon < ::LinkThumbnailer::Scrapers::Default::Base

        def value
          modelize(to_uri(href)).to_s
        end

        private

        def to_uri(href)
          ::URI.parse(href)
        rescue ::URI::InvalidURIError
          nil
        end

        def href
          node.attributes['href'].value.to_s if node
        end

        def node
          document.xpath("//link[contains(@rel, 'icon')]").first
        end

        def modelize(uri)
          model_class.new(uri)
        end

      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
link_thumbnailer-3.3.1 lib/link_thumbnailer/scrapers/default/favicon.rb
link_thumbnailer-3.3.0 lib/link_thumbnailer/scrapers/default/favicon.rb
link_thumbnailer-3.2.1 lib/link_thumbnailer/scrapers/default/favicon.rb
link_thumbnailer-3.2.0 lib/link_thumbnailer/scrapers/default/favicon.rb
link_thumbnailer-3.1.2 lib/link_thumbnailer/scrapers/default/favicon.rb
link_thumbnailer-3.1.1 lib/link_thumbnailer/scrapers/default/favicon.rb
link_thumbnailer-3.1.0 lib/link_thumbnailer/scrapers/default/favicon.rb
link_thumbnailer-3.0.3 lib/link_thumbnailer/scrapers/default/favicon.rb
link_thumbnailer-3.0.2 lib/link_thumbnailer/scrapers/default/favicon.rb
link_thumbnailer-3.0.1 lib/link_thumbnailer/scrapers/default/favicon.rb
link_thumbnailer-3.0.0 lib/link_thumbnailer/scrapers/default/favicon.rb
link_thumbnailer-2.6.1 lib/link_thumbnailer/scrapers/default/favicon.rb
link_thumbnailer-2.6.0 lib/link_thumbnailer/scrapers/default/favicon.rb
link_thumbnailer-2.5.2 lib/link_thumbnailer/scrapers/default/favicon.rb
link_thumbnailer-2.5.1 lib/link_thumbnailer/scrapers/default/favicon.rb
link_thumbnailer-2.5.0 lib/link_thumbnailer/scrapers/default/favicon.rb
link_thumbnailer-2.4.0 lib/link_thumbnailer/scrapers/default/favicon.rb
link_thumbnailer-2.3.2 lib/link_thumbnailer/scrapers/default/favicon.rb
link_thumbnailer-2.3.1 lib/link_thumbnailer/scrapers/default/favicon.rb
link_thumbnailer-2.3.0 lib/link_thumbnailer/scrapers/default/favicon.rb