Class: Numeric
- Inherits:
-
Object
- Object
- Numeric
- Defined in:
- lib/java-buildpack-utils/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
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/java-buildpack-utils/format_duration.rb', line 26 def duration remainder = self hours = (remainder / HOUR).to_int remainder -= HOUR * hours minutes = (remainder / MINUTE).to_int remainder -= MINUTE * minutes if hours > 0 return "#{hours}h #{minutes}m" end seconds = (remainder / SECOND).to_int remainder -= SECOND * seconds if minutes > 0 return "#{minutes}m #{seconds}s" end tenths = (remainder / TENTH).to_int "#{seconds}.#{tenths}s" end |