Sha256: 70fa59e5bef828ac5b39e373c55112091747789fd9c0756f00e681031ff88055

Contents?: true

Size: 365 Bytes

Versions: 2

Compression:

Stored size: 365 Bytes

Contents

# frozen_string_literal: true

module LinkThumbnailer
  module Graders
    class LinkDensity < ::LinkThumbnailer::Graders::Base

      def call
        return 0.0 if text.length == 0
        1.0 - (links.count.to_f / text.length.to_f)
      end

      private

      def links
        node.css('a').map(&:text).compact.reject(&:empty?)
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
link_thumbnailer-3.4.0 lib/link_thumbnailer/graders/link_density.rb
link_thumbnailer-3.3.2 lib/link_thumbnailer/graders/link_density.rb