Class: RubyCritic::AnalysedModulesCollection
- Inherits:
-
Object
- Object
- RubyCritic::AnalysedModulesCollection
- Defined in:
- lib/skunk/rubycritic/analysed_modules_collection.rb
Overview
Extends RubyCritic::AnalysedModulesCollection to add Skunk analysis methods
Instance Method Summary collapse
-
#analysed_modules_count ⇒ Integer
Returns the count of non-test modules.
-
#files_as_hash ⇒ Array<Hash>
Returns files as an array of hashes (for JSON serialization).
-
#non_test_modules ⇒ Array<RubyCritic::AnalysedModule>
Returns only non-test modules (excludes test and spec directories).
-
#skunk_score_average ⇒ Float
Returns the average Skunk score across all non-test modules.
-
#skunk_score_total ⇒ Float
Returns the total Skunk score across all non-test modules.
-
#sorted_modules ⇒ Array<RubyCritic::AnalysedModule>
Returns modules sorted by Skunk score in descending order (worst first).
-
#to_hash ⇒ Hash
Returns a hash representation of the analysis results.
-
#total_churn_times_cost ⇒ Float
Returns the total churn times cost across all non-test modules.
-
#worst_module ⇒ RubyCritic::AnalysedModule?
Returns the module with the highest Skunk score (worst performing).
Instance Method Details
#analysed_modules_count ⇒ Integer
Returns the count of non-test modules
10 11 12 |
# File 'lib/skunk/rubycritic/analysed_modules_collection.rb', line 10 def analysed_modules_count @analysed_modules_count ||= non_test_modules.count end |
#files_as_hash ⇒ Array<Hash>
Returns files as an array of hashes (for JSON serialization)
70 71 72 |
# File 'lib/skunk/rubycritic/analysed_modules_collection.rb', line 70 def files_as_hash @files_as_hash ||= sorted_modules.map(&:to_hash) end |
#non_test_modules ⇒ Array<RubyCritic::AnalysedModule>
Returns only non-test modules (excludes test and spec directories)
48 49 50 51 52 |
# File 'lib/skunk/rubycritic/analysed_modules_collection.rb', line 48 def non_test_modules @non_test_modules ||= reject do |a_module| test_module?(a_module) end end |
#skunk_score_average ⇒ Float
Returns the average Skunk score across all non-test modules
22 23 24 25 26 |
# File 'lib/skunk/rubycritic/analysed_modules_collection.rb', line 22 def skunk_score_average return 0.0 if analysed_modules_count.zero? (skunk_score_total.to_d / analysed_modules_count).to_f.round(2) end |
#skunk_score_total ⇒ Float
Returns the total Skunk score across all non-test modules
16 17 18 |
# File 'lib/skunk/rubycritic/analysed_modules_collection.rb', line 16 def skunk_score_total @skunk_score_total ||= non_test_modules.sum(&:skunk_score) end |
#sorted_modules ⇒ Array<RubyCritic::AnalysedModule>
Returns modules sorted by Skunk score in descending order (worst first)
42 43 44 |
# File 'lib/skunk/rubycritic/analysed_modules_collection.rb', line 42 def sorted_modules @sorted_modules ||= non_test_modules.sort_by(&:skunk_score).reverse! end |
#to_hash ⇒ Hash
Returns a hash representation of the analysis results
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/skunk/rubycritic/analysed_modules_collection.rb', line 56 def to_hash { analysed_modules_count: analysed_modules_count, skunk_score_total: skunk_score_total, skunk_score_average: skunk_score_average, total_churn_times_cost: total_churn_times_cost, worst_pathname: worst_module&.pathname, worst_score: worst_module&.skunk_score, files: files_as_hash } end |
#total_churn_times_cost ⇒ Float
Returns the total churn times cost across all non-test modules
30 31 32 |
# File 'lib/skunk/rubycritic/analysed_modules_collection.rb', line 30 def total_churn_times_cost @total_churn_times_cost ||= non_test_modules.sum(&:churn_times_cost) end |
#worst_module ⇒ RubyCritic::AnalysedModule?
Returns the module with the highest Skunk score (worst performing)
36 37 38 |
# File 'lib/skunk/rubycritic/analysed_modules_collection.rb', line 36 def worst_module @worst_module ||= sorted_modules.first end |