Class: RubyCritic::AnalysedModule
- Inherits:
-
Object
- Object
- RubyCritic::AnalysedModule
- Defined in:
- lib/rubycritic/core/analysed_module.rb
Constant Summary collapse
- COMPLEXITY_FACTOR =
Complexity is reduced by a factor of 25 when calculating cost
25.0
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #complexity_per_method ⇒ Object
- #cost ⇒ Object
- #file_location ⇒ Object
- #file_name ⇒ Object
- #line_count ⇒ Object
- #path ⇒ Object
- #rating ⇒ Object
- #smells? ⇒ Boolean
- #smells_at_location(location) ⇒ Object
- #smells_count ⇒ Object
- #to_h ⇒ Object
- #to_json(*options) ⇒ Object
Instance Method Details
#<=>(other) ⇒ Object
71 72 73 |
# File 'lib/rubycritic/core/analysed_module.rb', line 71 def <=>(other) [.to_s, name] <=> [other..to_s, other.name] end |
#complexity_per_method ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/rubycritic/core/analysed_module.rb', line 51 def complexity_per_method if methods_count.zero? 'N/A' else complexity.fdiv(methods_count).round(1) end end |
#cost ⇒ Object
42 43 44 45 |
# File 'lib/rubycritic/core/analysed_module.rb', line 42 def cost @cost ||= smells.map(&:cost).inject(0.0, :+) + (complexity / COMPLEXITY_FACTOR) end |
#file_location ⇒ Object
30 31 32 |
# File 'lib/rubycritic/core/analysed_module.rb', line 30 def file_location pathname.dirname end |
#file_name ⇒ Object
34 35 36 |
# File 'lib/rubycritic/core/analysed_module.rb', line 34 def file_name pathname.basename end |
#line_count ⇒ Object
38 39 40 |
# File 'lib/rubycritic/core/analysed_module.rb', line 38 def line_count File.read(path).each_line.count end |
#path ⇒ Object
26 27 28 |
# File 'lib/rubycritic/core/analysed_module.rb', line 26 def path @path ||= pathname.to_s end |
#rating ⇒ Object
47 48 49 |
# File 'lib/rubycritic/core/analysed_module.rb', line 47 def @rating ||= Rating.from_cost(cost) end |
#smells? ⇒ Boolean
63 64 65 |
# File 'lib/rubycritic/core/analysed_module.rb', line 63 def smells? !smells.empty? end |
#smells_at_location(location) ⇒ Object
67 68 69 |
# File 'lib/rubycritic/core/analysed_module.rb', line 67 def smells_at_location(location) smells.select { |smell| smell.at_location?(location) } end |
#smells_count ⇒ Object
59 60 61 |
# File 'lib/rubycritic/core/analysed_module.rb', line 59 def smells_count smells.count end |
#to_h ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/rubycritic/core/analysed_module.rb', line 75 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: } end |
#to_json(*options) ⇒ Object
90 91 92 |
# File 'lib/rubycritic/core/analysed_module.rb', line 90 def to_json(*) to_h.to_json(*) end |