Class: Entruby::Overview
- Inherits:
-
Object
- Object
- Entruby::Overview
- Defined in:
- lib/entruby.rb
Constant Summary collapse
- COMPLEX_FUNCTION_PARAMS =
7- HIGH_COUPLING_METRIC =
0.7- HUGE_FUNCTION_COL =
50
Instance Attribute Summary collapse
-
#metrics ⇒ Object
readonly
Returns the value of attribute metrics.
Instance Method Summary collapse
- #index ⇒ Object
-
#initialize(couplings) ⇒ Overview
constructor
A new instance of Overview.
- #report ⇒ Object
Constructor Details
#initialize(couplings) ⇒ Overview
Returns a new instance of Overview.
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/entruby.rb', line 108 def initialize(couplings) huge_functions = couplings.count { |c| c[:col] >= HUGE_FUNCTION_COL } complex_functions = couplings.count { |c| c[:params].size >= COMPLEX_FUNCTION_PARAMS } couplers = couplings.count { |c| c[:metric] >= HIGH_COUPLING_METRIC } @metrics = [ OverviewMetric.new("Excessive Couplers", "(Metric >= 0.7)", couplers, 3), OverviewMetric.new("Complex Functions", "(Params >= 7)", complex_functions, 2), OverviewMetric.new("Huge Functions", "(CoL >= 50)", huge_functions, 1), ] end |
Instance Attribute Details
#metrics ⇒ Object (readonly)
Returns the value of attribute metrics.
102 103 104 |
# File 'lib/entruby.rb', line 102 def metrics @metrics end |
Instance Method Details
#index ⇒ Object
123 124 125 |
# File 'lib/entruby.rb', line 123 def index metrics.reduce(0.0) { |memo, metric| memo + metric.value * metric.weight } end |
#report ⇒ Object
119 120 121 |
# File 'lib/entruby.rb', line 119 def report {index: index, metrics: metrics.map(&:as_json)} end |