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
- #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(*a) ⇒ Object
Instance Method Details
#<=>(other) ⇒ Object
66 67 68 |
# File 'lib/rubycritic/core/analysed_module.rb', line 66 def <=>(other) [.to_s, name] <=> [other..to_s, other.name] end |
#complexity_per_method ⇒ Object
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 |
#cost ⇒ Object
38 39 40 |
# File 'lib/rubycritic/core/analysed_module.rb', line 38 def cost @cost ||= smells.map(&:cost).inject(0, :+) + (complexity / 25) end |
#file_location ⇒ Object
26 27 28 |
# File 'lib/rubycritic/core/analysed_module.rb', line 26 def file_location pathname.dirname end |
#file_name ⇒ Object
30 31 32 |
# File 'lib/rubycritic/core/analysed_module.rb', line 30 def file_name pathname.basename end |
#line_count ⇒ Object
34 35 36 |
# File 'lib/rubycritic/core/analysed_module.rb', line 34 def line_count File.read(path).each_line.count end |
#path ⇒ Object
22 23 24 |
# File 'lib/rubycritic/core/analysed_module.rb', line 22 def path @path ||= pathname.to_s end |
#rating ⇒ Object
42 43 44 |
# File 'lib/rubycritic/core/analysed_module.rb', line 42 def @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_count ⇒ Object
54 55 56 |
# File 'lib/rubycritic/core/analysed_module.rb', line 54 def smells_count smells.count end |
#to_h ⇒ Object
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: } 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 |