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
GB()
click to toggle source
# File lib/rbfind/humansiz.rb, line 35 def GB ; self * G ; end
GiB()
click to toggle source
# File lib/rbfind/humansiz.rb, line 48 def GiB ; self * Gb ; end
MB()
click to toggle source
# File lib/rbfind/humansiz.rb, line 34 def MB ; self * M ; end
MiB()
click to toggle source
# File lib/rbfind/humansiz.rb, line 47 def MiB ; self * Mb ; end
TB()
click to toggle source
# File lib/rbfind/humansiz.rb, line 36 def TB ; self * T ; end
TiB()
click to toggle source
# File lib/rbfind/humansiz.rb, line 49 def TiB ; self * Tb ; end
kB()
click to toggle source
# File lib/rbfind/humansiz.rb, line 33 def kB ; self * K ; end
kiB()
click to toggle source
# File lib/rbfind/humansiz.rb, line 46 def kiB ; self * Kb ; end
t()
click to toggle source
# File lib/rbfind/humansiz.rb, line 100 def t ; Time.to_unit to_i ; end
to_h() → str
click to toggle source
To human readable with decimal prefixes.
4096.to_h #=> " 4.1kB"
# 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_hib() → str
click to toggle source
To human readable with binary prefixes.
4096.to_hib #=> " 4.0kiB"
# 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