Class: Rubycritic::AnalysedModule
- Inherits:
-
Object
- Object
- Rubycritic::AnalysedModule
- Defined in:
- lib/rubycritic/core/analysed_module.rb
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #complexity_per_method ⇒ Object
- #cost ⇒ Object
- #path ⇒ Object
- #rating ⇒ Object
- #smells? ⇒ Boolean
- #smells_at_location(location) ⇒ Object
- #to_h ⇒ Object
- #to_json(*a) ⇒ Object
Instance Method Details
#<=>(other) ⇒ Object
45 46 47 |
# File 'lib/rubycritic/core/analysed_module.rb', line 45 def <=>(other) [.to_s, name] <=> [other..to_s, other.name] end |
#complexity_per_method ⇒ Object
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 |
#cost ⇒ Object
21 22 23 |
# File 'lib/rubycritic/core/analysed_module.rb', line 21 def cost @cost ||= smells.map(&:cost).inject(0, :+) + (complexity / 25) end |
#path ⇒ Object
17 18 19 |
# File 'lib/rubycritic/core/analysed_module.rb', line 17 def path @path ||= pathname.to_s end |
#rating ⇒ Object
25 26 27 |
# File 'lib/rubycritic/core/analysed_module.rb', line 25 def @rating ||= Rating.from_cost(cost) end |
#smells? ⇒ 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_h ⇒ Object
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: } 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 |