Class: Stats::Mean
Instance Attribute Summary collapse
-
#n ⇒ Object
Returns the value of attribute n.
-
#sum ⇒ Object
Returns the value of attribute sum.
Instance Method Summary collapse
- #add(d) ⇒ Object
- #get_value ⇒ Object
-
#initialize(d) ⇒ Mean
constructor
A new instance of Mean.
- #merge(stat) ⇒ Object
- #remove(d) ⇒ Object
Methods inherited from StatsType
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
#n ⇒ Object
Returns the value of attribute n.
48 49 50 |
# File 'lib/shades/stats.rb', line 48 def n @n end |
#sum ⇒ Object
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_value ⇒ Object
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 |