Class: Numeric
- Inherits:
-
Object
- Object
- Numeric
- Defined in:
- lib/buildpack_support/format_duration.rb
Overview
A mixin that adds the ability to format a Numeric
as a user-readable duration
Instance Method Summary collapse
-
#duration ⇒ String
Formats a number as a user-readable duration.
Instance Method Details
#duration ⇒ String
Formats a number as a user-readable duration
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/buildpack_support/format_duration.rb', line 25 def duration remainder = self hours = (remainder / HOUR).to_int remainder -= HOUR * hours minutes = (remainder / MINUTE).to_int remainder -= MINUTE * minutes return "#{hours}h #{minutes}m" if hours > 0 seconds = (remainder / SECOND).to_int remainder -= SECOND * seconds return "#{minutes}m #{seconds}s" if minutes > 0 tenths = (remainder / TENTH).to_int "#{seconds}.#{tenths}s" end |