Sha256: 1eba4e6fb328d44433e0819a687dec5bef999b1d5b54f999693de7dd242cf35b

Contents?: true

Size: 1.06 KB

Versions: 14

Compression:

Stored size: 1.06 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 + 1) }.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 = 1)
          model_class.new(node, text, i)
        end

      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
link_thumbnailer-2.6.1 lib/link_thumbnailer/scrapers/default/description.rb
link_thumbnailer-2.6.0 lib/link_thumbnailer/scrapers/default/description.rb
link_thumbnailer-2.5.2 lib/link_thumbnailer/scrapers/default/description.rb
link_thumbnailer-2.5.1 lib/link_thumbnailer/scrapers/default/description.rb
link_thumbnailer-2.5.0 lib/link_thumbnailer/scrapers/default/description.rb
link_thumbnailer-2.4.0 lib/link_thumbnailer/scrapers/default/description.rb
link_thumbnailer-2.3.2 lib/link_thumbnailer/scrapers/default/description.rb
link_thumbnailer-2.3.1 lib/link_thumbnailer/scrapers/default/description.rb
link_thumbnailer-2.3.0 lib/link_thumbnailer/scrapers/default/description.rb
link_thumbnailer-2.2.3 lib/link_thumbnailer/scrapers/default/description.rb
link_thumbnailer-2.2.2 lib/link_thumbnailer/scrapers/default/description.rb
link_thumbnailer-2.2.1 lib/link_thumbnailer/scrapers/default/description.rb
link_thumbnailer-2.2.0 lib/link_thumbnailer/scrapers/default/description.rb
link_thumbnailer-2.1.0 lib/link_thumbnailer/scrapers/default/description.rb