Created
June 6, 2016 07:22
-
-
Save Tyralion/aa55a459d9a641fdf8ae5e4724cf6989 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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