Module: Console::Clock
- Defined in:
- lib/console/clock.rb
Overview
A simple clock utility for tracking and formatting time.
Class Method Summary collapse
-
.formatted_duration(duration) ⇒ Object
Format a duration in seconds as a human readable string.
- .now ⇒ Object
Class Method Details
.formatted_duration(duration) ⇒ Object
Format a duration in seconds as a human readable string.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/console/clock.rb', line 13 def self.formatted_duration(duration) if duration < 60.0 return "#{duration.round(2)}s" end duration /= 60.0 if duration < 60.0 return "#{duration.floor}m" end duration /= 60.0 if duration < 24.0 return "#{duration.floor}h" end duration /= 24.0 return "#{duration.floor}d" end |
.now ⇒ Object
36 37 38 |
# File 'lib/console/clock.rb', line 36 def self.now ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) end |