Sha256: 9b9f66cf6114bedbe8d77508cd933ec2c05c5bd5af2f2b76b9dfd066d7494857

Contents?: true

Size: 1.58 KB

Versions: 12

Compression:

Stored size: 1.58 KB

Contents

# frozen_string_literal: true

require_relative 'base_report'

module Reek
  module Report
    #
    # Generates a sorted, text summary of smells in examiners
    #
    # @public
    #
    class TextReport < BaseReport
      # @public
      def initialize(*args)
        super(*args)

        print progress_formatter.header
      end

      # @public
      def add_examiner(examiner)
        print progress_formatter.progress examiner
        super(examiner)
      end

      # @public
      def show
        sort_examiners if smells?
        print progress_formatter.footer
        display_summary
        display_total_smell_count
      end

      private

      def smell_summaries
        examiners.map { |ex| summarize_single_examiner(ex) }.reject(&:empty?)
      end

      def display_summary
        smell_summaries.each { |smell| puts smell }
      end

      def display_total_smell_count
        return unless examiners.size > 1

        print total_smell_count_message
      end

      def summarize_single_examiner(examiner)
        result = heading_formatter.header(examiner)
        if examiner.smelly?
          formatted_list = warning_formatter.format_list(examiner.smells)
          result += ":\n#{formatted_list}"
        end
        result
      end

      def sort_examiners
        examiners.sort_by!(&:smells_count).reverse! if sort_by_issue_count
      end

      def total_smell_count_message
        colour = smells? ? WARNINGS_COLOR : NO_WARNINGS_COLOR
        Rainbow("#{total_smell_count} total warning#{total_smell_count == 1 ? '' : 's'}\n").color(colour)
      end
    end
  end
end

Version data entries

12 entries across 10 versions & 2 rubygems

Version Path
reek-5.5.0 lib/reek/report/text_report.rb
reek-5.4.1 lib/reek/report/text_report.rb
reek-5.4.0 lib/reek/report/text_report.rb
reek-5.3.2 lib/reek/report/text_report.rb
reek-5.3.1 lib/reek/report/text_report.rb
reek-5.3.0 lib/reek/report/text_report.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/lib/reek/report/text_report.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/lib/reek/report/text_report.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/lib/reek/report/text_report.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/lib/reek/report/text_report.rb
reek-5.2.0 lib/reek/report/text_report.rb
reek-5.1.0 lib/reek/report/text_report.rb