Class: Infobar::Timer
Instance Attribute Summary collapse
-
#fifo ⇒ Object
readonly
Returns the value of attribute fifo.
-
#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
Instance Attribute Details
#fifo ⇒ Object (readonly)
Returns the value of attribute fifo.
14 15 16 |
# File 'lib/infobar/timer.rb', line 14 def fifo @fifo end |
#n ⇒ Object (readonly)
Returns the value of attribute n.
12 13 14 |
# File 'lib/infobar/timer.rb', line 12 def n @n end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
10 11 12 |
# File 'lib/infobar/timer.rb', line 10 def x @x end |
Instance Method Details
#add(time, count) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/infobar/timer.rb', line 16 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
41 42 43 |
# File 'lib/infobar/timer.rb', line 41 def average_time @x end |
#rate ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/infobar/timer.rb', line 33 def rate if @x.zero? 0.0 else 1.0 / @x end end |