Class: Infobar::Timer
Instance Attribute Summary collapse
-
#n ⇒ Object
readonly
Returns the value of attribute n.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
Instance Method Summary collapse
- #add(time, count) ⇒ Object
- #average_time ⇒ Object
-
#initialize ⇒ Timer
constructor
A new instance of Timer.
- #rate ⇒ Object
Constructor Details
#initialize ⇒ Timer
Returns a new instance of Timer.
2 3 4 5 |
# File 'lib/infobar/timer.rb', line 2 def initialize @n = 0 @x = 0.0 end |
Instance Attribute Details
#n ⇒ Object (readonly)
Returns the value of attribute n.
9 10 11 |
# File 'lib/infobar/timer.rb', line 9 def n @n end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
7 8 9 |
# File 'lib/infobar/timer.rb', line 7 def x @x end |
Instance Method Details
#add(time, count) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/infobar/timer.rb', line 11 def add(time, count) case @n when 0 @n += 1 when 1 @n -= 1 duration = time - @time_last self << (duration / @count_last) self << (duration / count.to_f) else duration = time - @time_last self << (duration / count.to_f) end @time_last, @count_last = time, count self end |
#average_time ⇒ Object
36 37 38 |
# File 'lib/infobar/timer.rb', line 36 def average_time @x end |
#rate ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/infobar/timer.rb', line 28 def rate if @x.zero? 0.0 else 1.0 / @x end end |