Class: Numeric
- Inherits:
-
Object
- Object
- Numeric
- Defined in:
- lib/rbfind/humansiz.rb,
lib/rbfind/humansiz.rb
Overview
sizes in bytes
Constant Summary collapse
- K =
:stopdoc:
1000
- M =
K * K
- G =
K * M
- T =
K * G
- Kb =
:stopdoc:
1024
- Mb =
Kb * Kb
- Gb =
Kb * Mb
- Tb =
Kb * Gb
- PREFIXES =
:nodoc:
" kMGTPEZY".scan /./
Instance Method Summary collapse
- #GB ⇒ Object
- #GiB ⇒ Object
-
#kB ⇒ Object
:startdoc:.
-
#kiB ⇒ Object
:startdoc:.
- #MB ⇒ Object
- #MiB ⇒ Object
- #t ⇒ Object
- #TB ⇒ Object
- #TiB ⇒ Object
-
#to_h ⇒ Object
:call-seq: num.to_h() -> str.
-
#to_hib ⇒ Object
:call-seq: num.to_hib() -> str.
Instance Method Details
#GB ⇒ Object
35 |
# File 'lib/rbfind/humansiz.rb', line 35 def GB ; self * G ; end |
#GiB ⇒ Object
48 |
# File 'lib/rbfind/humansiz.rb', line 48 def GiB ; self * Gb ; end |
#MB ⇒ Object
34 |
# File 'lib/rbfind/humansiz.rb', line 34 def MB ; self * M ; end |
#MiB ⇒ Object
47 |
# File 'lib/rbfind/humansiz.rb', line 47 def MiB ; self * Mb ; end |
#TB ⇒ Object
36 |
# File 'lib/rbfind/humansiz.rb', line 36 def TB ; self * T ; end |
#TiB ⇒ Object
49 |
# File 'lib/rbfind/humansiz.rb', line 49 def TiB ; self * Tb ; end |
#to_h ⇒ Object
:call-seq:
num.to_h() -> str
To human readable with decimal prefixes.
4096.to_h #=> " 4.1kB"
60 61 62 63 64 65 66 |
# 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 ⇒ Object
:call-seq:
num.to_hib() -> str
To human readable with binary prefixes.
4096.to_hib #=> " 4.0kiB"
75 76 77 78 79 80 81 |
# 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 |