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


66
67
68
# File 'lib/rubycritic/core/analysed_module.rb', line 66

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

#complexity_per_methodObject


46
47
48
49
50
51
52
# File 'lib/rubycritic/core/analysed_module.rb', line 46

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

#costObject


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

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

#file_locationObject


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

def file_location
  pathname.dirname
end

#file_nameObject


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

def file_name
  pathname.basename
end

#line_countObject


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

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

#pathObject


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

def path
  @path ||= pathname.to_s
end

#ratingObject


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

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

#smells?Boolean


58
59
60
# File 'lib/rubycritic/core/analysed_module.rb', line 58

def smells?
  !smells.empty?
end

#smells_at_location(location) ⇒ Object


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

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

#smells_countObject


54
55
56
# File 'lib/rubycritic/core/analysed_module.rb', line 54

def smells_count
  smells.count
end

#to_hObject


70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/rubycritic/core/analysed_module.rb', line 70

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


85
86
87
# File 'lib/rubycritic/core/analysed_module.rb', line 85

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