Class: Timer
- Inherits:
-
Object
- Object
- Timer
- Defined in:
- lib/timer.rb
Class Method Summary collapse
Class Method Details
.humanize(secs) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/timer.rb', line 14 def self.humanize secs [[60, :seconds], [60, :minutes], [24, :hours], [1000, :days]].map{ |count, name| if secs > 0 secs, n = secs.divmod(count) "#{n.to_i} #{name}" end }.compact.reverse.join(' ') end |
.starter ⇒ Object
2 3 4 5 |
# File 'lib/timer.rb', line 2 def self.starter File.open(".timer", "a") "Timer started. Go!!!" end |
.stoper ⇒ Object
7 8 9 10 11 12 |
# File 'lib/timer.rb', line 7 def self.stoper time = Time.now - File.mtime(".timer") rescue nil # "It took #{humanize(time)}." rescue nil File.open(".timer", "a"){|f|f.puts "#{time} seconds"} if time time ? "It took #{humanize(time)}." : "You haven't started yet. Type 'starter' to begin and 'stoper' to end" end |