Class: Numeric
- Inherits:
-
Object
- Object
- Numeric
- Defined in:
- lib/blinkr/hacks.rb
Instance Method Summary collapse
Instance Method Details
#duration ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/blinkr/hacks.rb', line 2 def duration rest, secs = self.divmod( 60 ) # self is the time difference t2 - t1 rest, mins = rest.divmod( 60 ) days, hours = rest.divmod( 24 ) # the above can be factored out as: # days, hours, mins, secs = self.duration_as_arr # # this is not so great, because it could include zero values: # self.duration_as_arr.zip ['Days','Hours','Minutes','Seconds']).flatten.join ' ' result = [] result << "#{days} days" if days > 0 result << "#{hours} hours" if hours > 0 result << "#{mins} minutes" if mins > 0 result << "#{secs} seconds" if secs > 0 result.join(' ') end |