Class: Stats::Mean

Inherits:
StatsType show all
Defined in:
lib/shades/stats.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from StatsType

get

Constructor Details

#initialize(d) ⇒ Mean

Returns a new instance of Mean.



50
51
52
53
# File 'lib/shades/stats.rb', line 50

def initialize(d)
  @sum = 0.0
  @n = 0.0
end

Instance Attribute Details

#nObject

Returns the value of attribute n.



48
49
50
# File 'lib/shades/stats.rb', line 48

def n
  @n
end

#sumObject

Returns the value of attribute sum.



47
48
49
# File 'lib/shades/stats.rb', line 47

def sum
  @sum
end

Instance Method Details

#add(d) ⇒ Object



55
56
57
58
# File 'lib/shades/stats.rb', line 55

def add(d)
  @sum += d
  @n += 1.0
end

#get_valueObject



70
71
72
# File 'lib/shades/stats.rb', line 70

def get_value
  @sum / @n
end

#merge(stat) ⇒ Object



65
66
67
68
# File 'lib/shades/stats.rb', line 65

def merge(stat)
  @sum += stat.sum
  @n += stat.n
end

#remove(d) ⇒ Object



60
61
62
63
# File 'lib/shades/stats.rb', line 60

def remove(d)
  @sum -= d
  @n -= 1.0
end