class Rubycrap::Crap

Attributes

file[R]
simplecov_information[R]

Public Class Methods

new(simplecov_information,file) click to toggle source
# File lib/rubycrap/crap.rb, line 7
def initialize(simplecov_information,file)
  @simplecov_information = simplecov_information
  @file = file
  @crap_methods= []
end

Public Instance Methods

calculate_with_flog() click to toggle source
# File lib/rubycrap/crap.rb, line 17
def calculate_with_flog
    flog_file(file["filename"])
    @flogger.each_by_score nil do |class_method, score, call_list|
      startline = @flogger.method_locations[class_method].split(":")[1]
      absolute_filename = @flogger.method_locations[class_method].split(":")[0]
      Rubycrap::logger.debug("flogger class method name: #{class_method}")
      flog_methodname = class_method.split("#")[1] || class_method.split("::")[1]
      Rubycrap::logger.debug("flogger method name: #{flog_methodname}")
      Rubycrap::logger.debug("flogger startline: #{startline}")
      Rubycrap::logger.debug("SIMPPLECOV : #{simplecov_information}")
      element = simplecov_information.detect {|f| f[:startline] == startline.to_i && f[:name] == flog_methodname}
      if element.to_s == ""
        Rubycrap::logger.debug("no match with simplecov for flogger class_method: #{class_method} startline: #{startline} ")
      else
        Rubycrap::logger.debug("flogger class_method: #{class_method} simplecov: #{element}")
        test_coverage = element[:coverage]
        @crap_methods << {:methodname => class_method, 
                         :flog_score => score ,
                         :filepath => absolute_filename, 
                         :startline => startline, 
                         :method_coverage => test_coverage, 
                         :crap_score => crap(score,test_coverage)}
      end
    end
    @crap_methods
end
crap(complexity,coverage) click to toggle source
# File lib/rubycrap/crap.rb, line 13
def crap(complexity,coverage)
  complexity ** 2 * (1 - coverage) ** 3 + complexity
end

Private Instance Methods

flog_file(filename) click to toggle source
# File lib/rubycrap/crap.rb, line 46
def flog_file(filename)
  FlogCLI.load_plugins
  options = FlogCLI.parse_options "-qma"
  @flogger = FlogCLI.new options
  @flogger.flog filename
  Rubycrap::logger.debug("flogger absolute_filename: #{filename}")
end