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



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

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

#complexity_per_methodObject



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

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

#costObject



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

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

#file_locationObject



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

def file_location
  pathname.dirname
end

#file_nameObject



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

def file_name
  pathname.basename
end

#line_countObject



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

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

#pathObject



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

def path
  @path ||= pathname.to_s
end

#ratingObject



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

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

#smells?Boolean

Returns:

  • (Boolean)


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

def smells?
  !smells.empty?
end

#smells_at_location(location) ⇒ Object



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

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

#smells_countObject



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

def smells_count
  smells.count
end

#to_hObject



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

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



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

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