Sha256: 0a45f0f3a835753fd4adeccdecc0e18a99c409d3d7a4b93d46c8ad0eacb23ed3

Contents?: true

Size: 876 Bytes

Versions: 19

Compression:

Stored size: 876 Bytes

Contents

module LinkThumbnailer
  module Graders
    class HtmlAttribute < ::LinkThumbnailer::Graders::Base

      attr_reader :attribute_name

      def initialize(description, attribute_name)
        super(description)
        @attribute_name = attribute_name.to_sym
      end

      def call(current_score)
        return 0 unless attribute?

        score = 0
        score -= 25 if negative?
        score += 25 if positive?
        score
      end

      private

      def attribute
        node[attribute_name]
      end

      def attribute?
        attribute && !attribute.empty?
      end

      def negative?
        attribute =~ negative_regex
      end

      def positive?
        attribute =~ positive_regex
      end

      def negative_regex
        config.negative_regex
      end

      def positive_regex
        config.positive_regex
      end

    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
link_thumbnailer-2.6.1 lib/link_thumbnailer/graders/html_attribute.rb
link_thumbnailer-2.6.0 lib/link_thumbnailer/graders/html_attribute.rb
link_thumbnailer-2.5.2 lib/link_thumbnailer/graders/html_attribute.rb
link_thumbnailer-2.5.1 lib/link_thumbnailer/graders/html_attribute.rb
link_thumbnailer-2.5.0 lib/link_thumbnailer/graders/html_attribute.rb
link_thumbnailer-2.4.0 lib/link_thumbnailer/graders/html_attribute.rb
link_thumbnailer-2.3.2 lib/link_thumbnailer/graders/html_attribute.rb
link_thumbnailer-2.3.1 lib/link_thumbnailer/graders/html_attribute.rb
link_thumbnailer-2.3.0 lib/link_thumbnailer/graders/html_attribute.rb
link_thumbnailer-2.2.3 lib/link_thumbnailer/graders/html_attribute.rb
link_thumbnailer-2.2.2 lib/link_thumbnailer/graders/html_attribute.rb
link_thumbnailer-2.2.1 lib/link_thumbnailer/graders/html_attribute.rb
link_thumbnailer-2.2.0 lib/link_thumbnailer/graders/html_attribute.rb
link_thumbnailer-2.1.0 lib/link_thumbnailer/graders/html_attribute.rb
link_thumbnailer-2.0.4 lib/link_thumbnailer/graders/html_attribute.rb
link_thumbnailer-2.0.3 lib/link_thumbnailer/graders/html_attribute.rb
link_thumbnailer-2.0.2 lib/link_thumbnailer/graders/html_attribute.rb
link_thumbnailer-2.0.1 lib/link_thumbnailer/graders/html_attribute.rb
link_thumbnailer-2.0.0 lib/link_thumbnailer/graders/html_attribute.rb