Class: SimplePerformer::Agger
- Inherits:
-
Object
- Object
- SimplePerformer::Agger
- Defined in:
- lib/simple_performer.rb
Instance Attribute Summary collapse
-
#count ⇒ Object
Returns the value of attribute count.
-
#name ⇒ Object
Returns the value of attribute name.
-
#sum ⇒ Object
Returns the value of attribute sum.
Instance Method Summary collapse
- #add(duration) ⇒ Object
- #avg ⇒ Object
-
#initialize(name) ⇒ Agger
constructor
A new instance of Agger.
- #to_s ⇒ Object
Constructor Details
#initialize(name) ⇒ Agger
Returns a new instance of Agger.
94 95 96 97 98 |
# File 'lib/simple_performer.rb', line 94 def initialize(name) @name = name @sum = 0.0 @count = 0 end |
Instance Attribute Details
#count ⇒ Object
Returns the value of attribute count.
92 93 94 |
# File 'lib/simple_performer.rb', line 92 def count @count end |
#name ⇒ Object
Returns the value of attribute name.
92 93 94 |
# File 'lib/simple_performer.rb', line 92 def name @name end |
#sum ⇒ Object
Returns the value of attribute sum.
92 93 94 |
# File 'lib/simple_performer.rb', line 92 def sum @sum end |
Instance Method Details
#add(duration) ⇒ Object
100 101 102 103 |
# File 'lib/simple_performer.rb', line 100 def add(duration) @sum += duration @count += 1 end |
#avg ⇒ Object
105 106 107 108 109 110 |
# File 'lib/simple_performer.rb', line 105 def avg if @count && @count > 0 return 1.0 * @sum / @count end return 0.0 end |
#to_s ⇒ Object
112 113 114 |
# File 'lib/simple_performer.rb', line 112 def to_s "Aggregator #{name}: count=#{count} avg=#{avg}" end |