Class: SimplePerformer::Agger

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_performer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#countObject

Returns the value of attribute count.



92
93
94
# File 'lib/simple_performer.rb', line 92

def count
  @count
end

#nameObject

Returns the value of attribute name.



92
93
94
# File 'lib/simple_performer.rb', line 92

def name
  @name
end

#sumObject

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

#avgObject



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_sObject



112
113
114
# File 'lib/simple_performer.rb', line 112

def to_s
  "Aggregator #{name}: count=#{count} avg=#{avg}"
end