Sha256: afeca95bcf5d6fa6b00e363f1a11416ad6c8041286f55a0b4a3797e208f6d4dc
Contents?: true
Size: 871 Bytes
Versions: 2
Compression:
Stored size: 871 Bytes
Contents
module Brewby module Timed attr_reader :start_time, :end_time def started? !@start_time.nil? end def ended? !@end_time.nil? end def in_progress? started? && !ended? end def start_timer @start_time = Time.now end def stop_timer @end_time = Time.now end def elapsed started? ? (@end_time || Time.now) - @start_time : 0 end def timer_for seconds time = seconds > 0 ? time_from_seconds(seconds) : [0, 0, 0] "%0.2d:%0.2d:%0.2d" % time end def countdown_for seconds sign = seconds > 0 ? "" : "+" sign + timer_for(seconds.abs) end def time_from_seconds seconds hours = seconds / 3600 seconds -= (hours * 3600) minutes = seconds / 60 seconds -= minutes * 60 [hours, minutes, seconds] end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
brewby-0.1.1 | lib/brewby/timed.rb |
brewby-0.1.0 | lib/brewby/timed.rb |