Class: Procps::Memsize
- Inherits:
-
Integer
- Object
- Integer
- Procps::Memsize
- Defined in:
- lib/procps/column_types/memsize.rb
Overview
The column type for a memsize
column.
Constant Summary collapse
- SUFFIXES =
%w(B K M G T)
Class Method Summary collapse
Instance Method Summary collapse
- #human ⇒ Object (also: #inspect)
-
#initialize(value) ⇒ Memsize
constructor
A new instance of Memsize.
Constructor Details
#initialize(value) ⇒ Memsize
Returns a new instance of Memsize.
12 13 14 |
# File 'lib/procps/column_types/memsize.rb', line 12 def initialize(value) super(value.to_i * 1024) end |
Class Method Details
.call(value) ⇒ Object
6 7 8 |
# File 'lib/procps/column_types/memsize.rb', line 6 def self.call(value) new(value) end |
Instance Method Details
#human ⇒ Object Also known as: inspect
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/procps/column_types/memsize.rb', line 16 def human step = 0 output = __getobj__.to_f while output > 1024 step += 1 output = output / 1024 break if step == SUFFIXES.size end fmt = output == output.to_i ? "%d%s" : "%.2f%s" format(fmt, output, SUFFIXES[step]) end |