Class: Rubycritic::AnalysedModule

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

Instance Method Summary collapse

Instance Method Details

#complexity_per_methodObject



30
31
32
33
34
35
36
# File 'lib/rubycritic/core/analysed_module.rb', line 30

def complexity_per_method
  if methods_count == 0
    "N/A"
  else
    complexity.fdiv(methods_count).round(1)
  end
end

#costObject



22
23
24
# File 'lib/rubycritic/core/analysed_module.rb', line 22

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

#pathObject



18
19
20
# File 'lib/rubycritic/core/analysed_module.rb', line 18

def path
  @path ||= pathname.to_s
end

#ratingObject



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

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

#smells?Boolean

Returns:

  • (Boolean)


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

def smells?
  !smells.empty?
end

#smells_at_location(location) ⇒ Object



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

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

#to_hObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rubycritic/core/analysed_module.rb', line 46

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(*a) ⇒ Object



61
62
63
# File 'lib/rubycritic/core/analysed_module.rb', line 61

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