Module: Enumerable

Defined in:
lib/production_log/analyzer.rb

Instance Method Summary collapse

Instance Method Details

#averageObject

Average of all the elements of the Enumerable

The Enumerable must respond to #length



19
20
21
# File 'lib/production_log/analyzer.rb', line 19

def average
  return self.sum / self.length.to_f
end

#sample_varianceObject

Sample variance of all the elements of the Enumerable

The Enumerable must respond to #length



28
29
30
31
32
# File 'lib/production_log/analyzer.rb', line 28

def sample_variance
  avg = self.average
  sum = self.inject(0) { |acc, i| acc + (i - avg) ** 2 }
  return (1 / self.length.to_f * sum)
end

#standard_deviationObject

Standard deviation of all the elements of the Enumerable

The Enumerable must respond to #length



39
40
41
# File 'lib/production_log/analyzer.rb', line 39

def standard_deviation
  return Math.sqrt(self.sample_variance)
end

#sumObject

Sum of all the elements of the Enumerable



10
11
12
# File 'lib/production_log/analyzer.rb', line 10

def sum
  return self.inject(0) { |acc, i| acc + i }
end