Sha256: ca7a4302d314989a76e8eb4992de325ac2dab15bab685b7aa1e19a20df42ea54

Contents?: true

Size: 981 Bytes

Versions: 8

Compression:

Stored size: 981 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]
      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

8 entries across 8 versions & 1 rubygems

Version Path
rubycritic-3.5.2 lib/rubycritic/commands/status_reporter.rb
rubycritic-3.5.1 lib/rubycritic/commands/status_reporter.rb
rubycritic-3.5.0 lib/rubycritic/commands/status_reporter.rb
rubycritic-3.4.0 lib/rubycritic/commands/status_reporter.rb
rubycritic-3.3.0 lib/rubycritic/commands/status_reporter.rb
rubycritic-3.2.3 lib/rubycritic/commands/status_reporter.rb
rubycritic-3.2.2 lib/rubycritic/commands/status_reporter.rb
rubycritic-3.2.1 lib/rubycritic/commands/status_reporter.rb