Sha256: 852c8e7f9cba56693c5ae47b326cd97d7b3f80a1f199dc895bec311e79f1cca2

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

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

2 entries across 2 versions & 1 rubygems

Version Path
link_thumbnailer-3.4.0 lib/link_thumbnailer/scrapers/default/description.rb
link_thumbnailer-3.3.2 lib/link_thumbnailer/scrapers/default/description.rb