class RubyCritic::AnalysedModule

Constants

COMPLEXITY_FACTOR

Complexity is reduced by a factor of 25 when calculating cost

Public Instance Methods

<=>(other) click to toggle source
# File lib/rubycritic/core/analysed_module.rb, line 76
def <=>(other)
  [rating.to_s, name] <=> [other.rating.to_s, other.name]
end
complexity_per_method() click to toggle source
# 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
cost() click to toggle source
# File lib/rubycritic/core/analysed_module.rb, line 43
def cost
  @cost ||= smells.map(&:cost).inject(0.0, :+) +
            (complexity / COMPLEXITY_FACTOR)
end
coverage_rating() click to toggle source
# File lib/rubycritic/core/analysed_module.rb, line 48
def coverage_rating
  @coverage_rating ||= Rating.from_cost(100 - coverage)
end
file_location() click to toggle source
# File lib/rubycritic/core/analysed_module.rb, line 31
def file_location
  pathname.dirname
end
file_name() click to toggle source
# File lib/rubycritic/core/analysed_module.rb, line 35
def file_name
  pathname.basename
end
line_count() click to toggle source
# File lib/rubycritic/core/analysed_module.rb, line 39
def line_count
  File.read(path).each_line.count
end
path() click to toggle source
# File lib/rubycritic/core/analysed_module.rb, line 27
def path
  @path ||= pathname.to_s
end
rating() click to toggle source
# File lib/rubycritic/core/analysed_module.rb, line 52
def rating
  @rating ||= Rating.from_cost(cost)
end
smells?() click to toggle source
# File lib/rubycritic/core/analysed_module.rb, line 68
def smells?
  !smells.empty?
end
smells_at_location(location) click to toggle source
# File lib/rubycritic/core/analysed_module.rb, line 72
def smells_at_location(location)
  smells.select { |smell| smell.at_location?(location) }
end
smells_count() click to toggle source
# File lib/rubycritic/core/analysed_module.rb, line 64
def smells_count
  smells.count
end
to_h() click to toggle source
# 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) click to toggle source
# File lib/rubycritic/core/analysed_module.rb, line 89
def to_json(*options)
  to_h.to_json(*options)
end