This class provides a very simple countdown object which can be used to drive time-boxed operations.
Upon initialization, the current time is noted, and calls to
remaining
will be relative to the start time and supplied
duration
(expressed in seconds).
# File lib/openshift-origin-node/utils/hourglass.rb, line 17 def initialize(duration) @duration = duration @start_time = Time.now @end_time = @start_time + @duration end
Returns the number of seconds elapsed since the start time.
# File lib/openshift-origin-node/utils/hourglass.rb, line 26 def elapsed (Time.now - @start_time).round end
Returns true
if the duration has been exceeded, otherwise
false.
# File lib/openshift-origin-node/utils/hourglass.rb, line 41 def expired? remaining.zero? end
Returns the number of seconds remaining until expiration, or zero if the hourglass has expired.
# File lib/openshift-origin-node/utils/hourglass.rb, line 34 def remaining [0, @duration - elapsed].max end