lib/skunk/cli/commands/status_reporter.rb in skunk-0.2.0 vs lib/skunk/cli/commands/status_reporter.rb in skunk-0.3.0

- old
+ new

@@ -1,7 +1,8 @@ # frozen_string_literal: true +require "erb" require "rubycritic/commands/status_reporter" require "terminal-table" module Skunk module Command @@ -9,33 +10,39 @@ class StatusReporter < RubyCritic::Command::StatusReporter attr_accessor :analysed_modules HEADINGS = %w[file stink_score churn_times_cost churn cost coverage].freeze + TEMPLATE = ERB.new(<<-TEMPL +<%= ttable %>\n +StinkScore Total: <%= total_stink_score %> +Modules Analysed: <%= analysed_modules_count %> +StinkScore Average: <%= stink_score_average %> +<% if worst %>Worst StinkScore: <%= worst.stink_score %> (<%= worst.pathname %>)<% end %> +TEMPL + ) + # Returns a status message with a table of all analysed_modules and # a stink score average def update_status_message opts = table_options.merge(headings: HEADINGS, rows: table) ttable = Terminal::Table.new(opts) - @status_message = "#{ttable}\n\n" - - @status_message += "StinkScore Total: #{total_stink_score}\n" - @status_message += "Modules Analysed: #{analysed_modules_count}\n" - @status_message += "StinkScore Average: #{stink_score}\n" - @status_message += "Worst StinkScore: #{worst.stink_score} (#{worst.pathname})\n" if worst + @status_message = TEMPLATE.result(binding) end private def analysed_modules_count @analysed_modules_count ||= non_test_modules.count end def non_test_modules - @non_test_modules ||= analysed_modules.reject { |x| x.pathname.to_s.start_with?("test", "spec")} + @non_test_modules ||= analysed_modules.reject do |a_module| + a_module.pathname.to_s.start_with?("test", "spec") + end end def worst @worst ||= sorted_modules.first end @@ -50,13 +57,13 @@ def total_churn_times_cost non_test_modules.map(&:churn_times_cost).sum end - def stink_score - return 0 if analysed_modules_count == 0 + def stink_score_average + return 0 if analysed_modules_count.zero? - total_stink_score.to_d / analysed_modules_count + (total_stink_score.to_d / analysed_modules_count).to_f end def table_options { style: {