Class: Rubycritic::AnalysedModule

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

Instance Method Summary collapse

Instance Method Details

#<=>(other) ⇒ Object



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

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

#complexity_per_methodObject



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

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

#costObject



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

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

#pathObject



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

def path
  @path ||= pathname.to_s
end

#ratingObject



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

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

#smells?Boolean

Returns:

  • (Boolean)


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

def smells?
  !smells.empty?
end

#smells_at_location(location) ⇒ Object



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

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

#to_hObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rubycritic/core/analysed_module.rb', line 49

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



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

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