Sha256: 0b468f53e2462361ca216834fda3c48870ba30889d67701bb6427827d17bbd73

Contents?: true

Size: 986 Bytes

Versions: 22

Compression:

Stored size: 986 Bytes

Contents

# frozen_string_literal: true

module RubyCritic
  module Command
    class StatusReporter
      attr_reader :status, :status_message, :score
      SUCCESS = 0
      SCORE_BELOW_MINIMUM = 1

      def initialize(options)
        @options = options
        @status = SUCCESS
      end

      def score=(input_score)
        @score = input_score.round(2)
        update_status
      end

      private

      def update_status
        @status = current_status
        update_status_message
      end

      def current_status
        satisfy_minimum_score_rule ? SUCCESS : SCORE_BELOW_MINIMUM
      end

      def satisfy_minimum_score_rule
        score >= @options[:minimum_score].to_f
      end

      def update_status_message
        case @status
        when SUCCESS
          @status_message = "Score: #{score}"
        when SCORE_BELOW_MINIMUM
          @status_message = "Score (#{score}) is below the minimum #{@options[:minimum_score]}"
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
rubycritic-4.8.0 lib/rubycritic/commands/status_reporter.rb
rubycritic-4.7.0 lib/rubycritic/commands/status_reporter.rb
rubycritic-4.6.1 lib/rubycritic/commands/status_reporter.rb
rubycritic-4.6.0 lib/rubycritic/commands/status_reporter.rb
rubycritic-4.5.2 lib/rubycritic/commands/status_reporter.rb
rubycritic-4.5.1 lib/rubycritic/commands/status_reporter.rb
rubycritic-4.5.0 lib/rubycritic/commands/status_reporter.rb
rubycritic-4.4.1 lib/rubycritic/commands/status_reporter.rb
rubycritic-4.4.0 lib/rubycritic/commands/status_reporter.rb
rubycritic-4.3.3 lib/rubycritic/commands/status_reporter.rb
rubycritic-4.3.2 lib/rubycritic/commands/status_reporter.rb
rubycritic-4.3.1 lib/rubycritic/commands/status_reporter.rb
rubycritic-4.3.0 lib/rubycritic/commands/status_reporter.rb
rubycritic-4.2.2 lib/rubycritic/commands/status_reporter.rb
rubycritic-4.2.1 lib/rubycritic/commands/status_reporter.rb
rubycritic-4.2.0 lib/rubycritic/commands/status_reporter.rb
rubycritic-simplecov-4.1.1 lib/rubycritic/commands/status_reporter.rb
rubycritic-simplecov-4.1.0 lib/rubycritic/commands/status_reporter.rb
rubycritic-4.1.0 lib/rubycritic/commands/status_reporter.rb
rubycritic-4.0.2 lib/rubycritic/commands/status_reporter.rb