Module: Sfdown::Fmt
- Defined in:
- lib/sfdown.rb
Overview
Human-readable formatting for sizes and durations.
Constant Summary collapse
- UNITS =
%w[B KB MB GB TB].freeze
Class Method Summary collapse
Class Method Details
.duration(secs) ⇒ Object
438 439 440 441 442 443 444 |
# File 'lib/sfdown.rb', line 438 def duration(secs) return format("%.1fs", secs) if secs < 60 m, s = secs.round.divmod(60) h, m = m.divmod(60) h.zero? ? format("%dm%02ds", m, s) : format("%dh%02dm%02ds", h, m, s) end |