Sha256: 0daddfa83d5590efe82cf4065b422c4a96587cf07bac56e6e197991bcd3dd6fd

Contents?: true

Size: 894 Bytes

Versions: 25

Compression:

Stored size: 894 Bytes

Contents

require 'link_thumbnailer/scrapers/base'

module LinkThumbnailer
  module Scrapers
    module Opengraph
      class Base < ::LinkThumbnailer::Scrapers::Base

        def applicable?
          meta.any? { |node| opengraph_node?(node) }
        end

        def value
          model.to_s
        end

        private

        def model
          modelize(node, node.attributes['content'].to_s) if node
        end

        def node
          @node ||= meta_xpath(attribute: attribute) ||
                      meta_xpath(attribute: attribute, key: :name)
        end

        def attribute
          "og:#{attribute_name}"
        end

        def opengraph_node?(node)
          node.attribute('name').to_s.start_with?('og:') ||
            node.attribute('property').to_s.start_with?('og:')
        end

        def meta
          document.css('meta')
        end

      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

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