Module: Rarity
- Defined in:
- lib/rarity.rb,
lib/rarity/version.rb
Defined Under Namespace
Classes: Optimiser, Runner, Tracker
Constant Summary collapse
- VERSION =
"0.1.1"
Class Method Summary collapse
Class Method Details
.to_human(number) ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/rarity.rb', line 4 def self.to_human(number) units = %w{B KB MB GB TB} if number > 0 e = (Math.log(number)/Math.log(1024)).floor s = "%.3f" % (number.to_f / 1024**e) return s.sub(/\.?0*$/, units[e]) else return "0 B" end end |