Class: RubyCritic::AnalysedModule

Inherits:
Object
  • Object
show all
Defined in:
lib/rubycritic/core/analysed_module.rb

Constant Summary collapse

COMPLEXITY_FACTOR =

Complexity is reduced by a factor of 25 when calculating cost

25.0

Instance Method Summary collapse

Instance Method Details

#<=>(other) ⇒ Object



76
77
78
# File 'lib/rubycritic/core/analysed_module.rb', line 76

def <=>(other)
  [rating.to_s, name] <=> [other.rating.to_s, other.name]
end

#complexity_per_methodObject



56
57
58
59
60
61
62
# File 'lib/rubycritic/core/analysed_module.rb', line 56

def complexity_per_method
  if methods_count.zero?
    'N/A'
  else
    complexity.fdiv(methods_count).round(1)
  end
end

#costObject



43
44
45
46
# File 'lib/rubycritic/core/analysed_module.rb', line 43

def cost
  @cost ||= smells.map(&:cost).inject(0.0, :+) +
            (complexity / COMPLEXITY_FACTOR)
end

#coverage_ratingObject



48
49
50
# File 'lib/rubycritic/core/analysed_module.rb', line 48

def coverage_rating
  @coverage_rating ||= Rating.from_cost(100 - coverage)
end

#file_locationObject



31
32
33
# File 'lib/rubycritic/core/analysed_module.rb', line 31

def file_location
  pathname.dirname
end

#file_nameObject



35
36
37
# File 'lib/rubycritic/core/analysed_module.rb', line 35

def file_name
  pathname.basename
end

#line_countObject



39
40
41
# File 'lib/rubycritic/core/analysed_module.rb', line 39

def line_count
  File.read(path).each_line.count
end

#pathObject



27
28
29
# File 'lib/rubycritic/core/analysed_module.rb', line 27

def path
  @path ||= pathname.to_s
end

#ratingObject



52
53
54
# File 'lib/rubycritic/core/analysed_module.rb', line 52

def rating
  @rating ||= Rating.from_cost(cost)
end

#smells?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/rubycritic/core/analysed_module.rb', line 68

def smells?
  !smells.empty?
end

#smells_at_location(location) ⇒ Object



72
73
74
# File 'lib/rubycritic/core/analysed_module.rb', line 72

def smells_at_location(location)
  smells.select { |smell| smell.at_location?(location) }
end

#smells_countObject



64
65
66
# File 'lib/rubycritic/core/analysed_module.rb', line 64

def smells_count
  smells.count
end

#to_hObject



80
81
82
83
84
85
86
87
# File 'lib/rubycritic/core/analysed_module.rb', line 80

def to_h
  {
    name: name, path: path, smells: smells,
    churn: churn, committed_at: committed_at, complexity: complexity,
    duplication: duplication, methods_count: methods_count, cost: cost,
    rating: rating
  }
end

#to_json(*options) ⇒ Object



89
90
91
# File 'lib/rubycritic/core/analysed_module.rb', line 89

def to_json(*options)
  to_h.to_json(*options)
end