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
- #coverage_rating ⇒ 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
76 77 78 |
# File 'lib/rubycritic/core/analysed_module.rb', line 76 def <=>(other) [.to_s, name] <=> [other..to_s, other.name] end |
#complexity_per_method ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/rubycritic/core/analysed_module.rb', line 56 def complexity_per_method if methods_count.zero? 'N/A' else complexity.fdiv(methods_count).round(1) end end |
#cost ⇒ Object
43 44 45 46 |
# File 'lib/rubycritic/core/analysed_module.rb', line 43 def cost @cost ||= smells.map(&:cost).inject(0.0, :+) + (complexity / COMPLEXITY_FACTOR) end |
#coverage_rating ⇒ Object
48 49 50 |
# File 'lib/rubycritic/core/analysed_module.rb', line 48 def @coverage_rating ||= Rating.from_cost(100 - coverage) end |
#file_location ⇒ Object
31 32 33 |
# File 'lib/rubycritic/core/analysed_module.rb', line 31 def file_location pathname.dirname end |
#file_name ⇒ Object
35 36 37 |
# File 'lib/rubycritic/core/analysed_module.rb', line 35 def file_name pathname.basename end |
#line_count ⇒ Object
39 40 41 |
# File 'lib/rubycritic/core/analysed_module.rb', line 39 def line_count File.read(path).each_line.count end |
#path ⇒ Object
27 28 29 |
# File 'lib/rubycritic/core/analysed_module.rb', line 27 def path @path ||= pathname.to_s end |
#rating ⇒ Object
52 53 54 |
# File 'lib/rubycritic/core/analysed_module.rb', line 52 def @rating ||= Rating.from_cost(cost) end |
#smells? ⇒ Boolean
68 69 70 |
# File 'lib/rubycritic/core/analysed_module.rb', line 68 def smells? !smells.empty? end |
#smells_at_location(location) ⇒ Object
72 73 74 |
# File 'lib/rubycritic/core/analysed_module.rb', line 72 def smells_at_location(location) smells.select { |smell| smell.at_location?(location) } end |
#smells_count ⇒ Object
64 65 66 |
# File 'lib/rubycritic/core/analysed_module.rb', line 64 def smells_count smells.count end |
#to_h ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/rubycritic/core/analysed_module.rb', line 80 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
89 90 91 |
# File 'lib/rubycritic/core/analysed_module.rb', line 89 def to_json(*) to_h.to_json(*) end |