Class: Rubycrap::Crap

Inherits:
Object
  • Object
show all
Defined in:
lib/rubycrap/crap.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(simplecov_information, file) ⇒ Crap

Returns a new instance of Crap.



7
8
9
10
11
# File 'lib/rubycrap/crap.rb', line 7

def initialize(simplecov_information,file)
  @simplecov_information = simplecov_information
  @file = file
  @crap_methods= []
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



6
7
8
# File 'lib/rubycrap/crap.rb', line 6

def file
  @file
end

#simplecov_informationObject (readonly)

Returns the value of attribute simplecov_information.



6
7
8
# File 'lib/rubycrap/crap.rb', line 6

def simplecov_information
  @simplecov_information
end

Instance Method Details

#calculate_with_flogObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# 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) ⇒ Object



13
14
15
# File 'lib/rubycrap/crap.rb', line 13

def crap(complexity,coverage)
  complexity ** 2 * (1 - coverage) ** 3 + complexity
end