class Numeric
Human readable sizes and times.
Examples:
4096.to_h # => " 4.1kB" 4096.to_hib # => " 4.0kiB" 1.MB # => 1000000 1.MiB # => 1048576 1.5.kiB # => 1536.0 1.h # => 3600 1.w # => 604800
Public Instance Methods
Source
# File lib/rbfind/humansiz.rb, line 60 def to_h n = 0 s = to_f while s >= K do s /= K ; n += 1 end format = n.zero? ? "%3d " : "%5.1f" (format % s) + (PREFIXES[ n]||"?") + "B" end
To human readable with decimal prefixes.
4096.to_h #=> " 4.1kB"
Source
# File lib/rbfind/humansiz.rb, line 75 def to_hib n = 0 s = to_f while s >= Kb do s /= Kb ; n += 1 end format = n.zero? ? "%4d " : "%6.1f" (format % s) + (PREFIXES[ n]||"?") + "iB" end
To human readable with binary prefixes.
4096.to_hib #=> " 4.0kiB"