Sha256: 26ea35c1e7f7a7fac367bdfa8a5dce9280e174dd5f8157ecd3d12c418b11205d

Contents?: true

Size: 980 Bytes

Versions: 7

Compression:

Stored size: 980 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

7 entries across 7 versions & 1 rubygems

Version Path
rubycritic-3.2.0 lib/rubycritic/commands/status_reporter.rb
rubycritic-3.1.3 lib/rubycritic/commands/status_reporter.rb
rubycritic-3.1.2 lib/rubycritic/commands/status_reporter.rb
rubycritic-3.1.1 lib/rubycritic/commands/status_reporter.rb
rubycritic-3.1.0 lib/rubycritic/commands/status_reporter.rb
rubycritic-3.0.0 lib/rubycritic/commands/status_reporter.rb
rubycritic-2.9.4 lib/rubycritic/commands/status_reporter.rb