Sha256: 88436d3f9b041bb196a82d71c1049cc1244d47421dfd00f5bef6ec0e7d61ef15

Contents?: true

Size: 933 Bytes

Versions: 1

Compression:

Stored size: 933 Bytes

Contents

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

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

      def score=(score)
        @score = 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]
      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

1 entries across 1 versions & 1 rubygems

Version Path
rubycritic-2.9.3 lib/rubycritic/commands/status_reporter.rb