Class: Entruby::Overview

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#metricsObject (readonly)

Returns the value of attribute metrics.



102
103
104
# File 'lib/entruby.rb', line 102

def metrics
  @metrics
end

Instance Method Details

#indexObject



123
124
125
# File 'lib/entruby.rb', line 123

def index
  metrics.reduce(0.0) { |memo, metric| memo + metric.value * metric.weight }
end

#reportObject



119
120
121
# File 'lib/entruby.rb', line 119

def report
  {index: index, metrics: metrics.map(&:as_json)}
end