Skip to content

Instantly share code, notes, and snippets.

@Tyralion
Created June 6, 2016 07:22
Show Gist options
  • Select an option

  • Save Tyralion/aa55a459d9a641fdf8ae5e4724cf6989 to your computer and use it in GitHub Desktop.

Select an option

Save Tyralion/aa55a459d9a641fdf8ae5e4724cf6989 to your computer and use it in GitHub Desktop.
module NumericExt
def humanize_time
secs = self
[
[60, :сек],
[60, :мин],
[24, :ч],
[1000, :д]
].freeze.map { |count, name|
if secs > 0
secs, n = secs.divmod(count)
"#{n.to_i} #{name}"
end
}.compact.reverse.join(' ')
end # humanize_time
end
class Numeric
include NumericExt
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment