Sha256: 78a8cb1c90df765a1405bfd0903fc0f2cf08f9df32872ff3eb502b7afb7a3e4d

Contents?: true

Size: 793 Bytes

Versions: 4

Compression:

Stored size: 793 Bytes

Contents

module RubyCritic
  module Formatter
    class BadgeFormatter
      COLORS = {
        0..59 => "red",
        60..69 => "orange",
        70..79 => "yellow",
        80..89 => "yellowgreen",
        90..94 => "green",
        95..100 => "brightgreen"
      }.freeze

      def initialize(analysed_modules)
        @percentage = analysed_modules.score.to_i
      end

      def generate_report
        readme_update
      end

      private

      attr_reader :percentage

      def readme_update
        color = COLORS.find { |range, _| range.include?(percentage) }.last
        badge = "![Code quality](https://img.shields.io/badge/quality-#{percentage}%25-#{color})"
        File.write("README.md", File.read("README.md").gsub(/!\[Code quality\]\(.*\)/, badge))
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
tangany-0.0.5 lib/ruby_critic/formatter/badge_formatter.rb
tangany-0.0.4 lib/ruby_critic/formatter/badge_formatter.rb
tangany-0.0.3 lib/ruby_critic/formatter/badge_formatter.rb
tangany-0.0.2 lib/ruby_critic/formatter/badge_formatter.rb