Sha256: db0ede488280cd885f22b2d77858c4fcc603029bb85a5602df30994e10892150

Contents?: true

Size: 1.08 KB

Versions: 11

Compression:

Stored size: 1.08 KB

Contents

require 'link_thumbnailer/scrapers/default/base'

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

        def value
          return model_from_meta.to_s if model_from_meta
          return model_from_body.to_s if model_from_body
          nil
        end

        private

        def model_from_meta
          modelize(node_from_meta, node_from_meta.attributes['content'].value) if node_from_meta
        end

        def model_from_body
          nodes_from_body.each_with_index.map { |node, i| modelize(node, node.text, i) }.sort.last
        end

        def node_from_meta
          @node_from_meta ||= meta_xpath(key: :name)
        end

        def nodes_from_body
          candidates.select { |node| valid_paragraph?(node) }
        end

        def valid_paragraph?(node)
          true
        end

        def candidates
          document.css('p,td')
        end

        def modelize(node, text, i = 0)
          model_class.new(node, text, i, nodes_from_body.count)
        end

      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
link_thumbnailer-3.3.1 lib/link_thumbnailer/scrapers/default/description.rb
link_thumbnailer-3.3.0 lib/link_thumbnailer/scrapers/default/description.rb
link_thumbnailer-3.2.1 lib/link_thumbnailer/scrapers/default/description.rb
link_thumbnailer-3.2.0 lib/link_thumbnailer/scrapers/default/description.rb
link_thumbnailer-3.1.2 lib/link_thumbnailer/scrapers/default/description.rb
link_thumbnailer-3.1.1 lib/link_thumbnailer/scrapers/default/description.rb
link_thumbnailer-3.1.0 lib/link_thumbnailer/scrapers/default/description.rb
link_thumbnailer-3.0.3 lib/link_thumbnailer/scrapers/default/description.rb
link_thumbnailer-3.0.2 lib/link_thumbnailer/scrapers/default/description.rb
link_thumbnailer-3.0.1 lib/link_thumbnailer/scrapers/default/description.rb
link_thumbnailer-3.0.0 lib/link_thumbnailer/scrapers/default/description.rb