Class: RubyCritic::AnalysedModule
- Inherits:
-
Object
- Object
- RubyCritic::AnalysedModule
- Defined in:
- lib/skunk/rubycritic/analysed_module.rb
Overview
Monkey-patches RubyCritic::AnalysedModule to add a skunk_score method
Constant Summary collapse
- PERFECT_COVERAGE =
100
Instance Method Summary collapse
-
#churn_times_cost ⇒ Integer
Returns the value of churn times cost.
-
#penalty_factor ⇒ Integer
Returns a numeric value that represents the penalty factor based on the lack of code coverage (not enough test cases for this module).
-
#skunk_score ⇒ Float
Returns a numeric value that represents the skunk_score of a module:.
-
#to_hash ⇒ Hash
Returns a hash with these attributes: - file - skunk_score - churn_times_cost - churn - cost - coverage.
Instance Method Details
#churn_times_cost ⇒ Integer
Returns the value of churn times cost.
50 51 52 53 |
# File 'lib/skunk/rubycritic/analysed_module.rb', line 50 def churn_times_cost safe_churn = churn.positive? ? churn : 1 @churn_times_cost ||= (safe_churn * cost).round(2) end |
#penalty_factor ⇒ Integer
Returns a numeric value that represents the penalty factor based on the lack of code coverage (not enough test cases for this module)
43 44 45 |
# File 'lib/skunk/rubycritic/analysed_module.rb', line 43 def penalty_factor PERFECT_COVERAGE - coverage.to_i end |
#skunk_score ⇒ Float
Returns a numeric value that represents the skunk_score of a module:
If module is perfectly covered, skunk score is the same as the ‘cost`
If module has no coverage, skunk score is a penalized value of ‘cost`
For now the skunk_score is calculated by multiplying ‘cost` times the lack of coverage.
For example:
When ‘cost` is 100 and module is perfectly covered: skunk_score => 100
When ‘cost` is 100 and module is not covered at all: skunk_score => 100 * 100 = 10_000
When ‘cost` is 100 and module is covered at 75%: skunk_score => 100 * 25 (percentage uncovered) = 2_500
33 34 35 36 37 |
# File 'lib/skunk/rubycritic/analysed_module.rb', line 33 def skunk_score return cost.round(2) if coverage == PERFECT_COVERAGE (cost * penalty_factor).round(2) end |
#to_hash ⇒ Hash
Returns a hash with these attributes:
- file
- skunk_score
- churn_times_cost
- churn
- cost
- coverage
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/skunk/rubycritic/analysed_module.rb', line 64 def to_hash { file: pathname.to_s, skunk_score: skunk_score, churn_times_cost: churn_times_cost, churn: churn, cost: cost.round(2), coverage: coverage.round(2) } end |