Module: RSpecTracer::TimeFormatter Private
- Defined in:
- lib/rspec_tracer/time_formatter.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Internal TimeFormatter — see RSpecTracer for the user-facing surface. Internal helper for human-friendly elapsed-time formatting in tracer log lines and the terminal reporter (e.g. “1 minute 23 seconds”).
Constant Summary collapse
- DEFAULT_PRECISION =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Internal constant.
2- SECONDS_PRECISION =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Internal constant.
5- UNITS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Internal constant.
{ second: 60, minute: 60, hour: 24, day: Float::INFINITY }.freeze
Class Method Summary collapse
-
.format_time(seconds) ⇒ Object
private
Internal helper for the tracer pipeline.
Class Method Details
.format_time(seconds) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Internal helper for the tracer pipeline.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rspec_tracer/time_formatter.rb', line 28 def self.format_time(seconds) return pluralize(format_duration(seconds), 'second') if seconds < 60 formatted_duration = UNITS.each_pair.with_object([]) do |(unit, count), duration| next unless seconds.positive? seconds, remainder = seconds.divmod(count) next if remainder.zero? duration << pluralize(format_duration(remainder), unit) end formatted_duration.reverse.join(' ') end |