Class: Lazylead::Allocated

Inherits:
Object
  • Object
show all
Defined in:
lib/lazylead/allocated.rb

Overview

Human readable format of allocated bytes within current process.

Author

Yurii Dubinka ([email protected])

Copyright

Copyright © 2019-2020 Yurii Dubinka

License

MIT

Instance Method Summary collapse

Constructor Details

#initialize(bytes = GetProcessMem.new.bytes.to_i) ⇒ Allocated

Returns a new instance of Allocated.



34
35
36
# File 'lib/lazylead/allocated.rb', line 34

def initialize(bytes = GetProcessMem.new.bytes.to_i)
  @bytes = bytes
end

Instance Method Details

#to_iObject



52
53
54
# File 'lib/lazylead/allocated.rb', line 52

def to_i
  @bytes
end

#to_sObject



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/lazylead/allocated.rb', line 38

def to_s
  if @bytes.nil?
    "?"
  elsif @bytes < 1024
    "#{@bytes}B"
  elsif @bytes < 1024 * 1024
    "#{(@bytes / 1024).round}KB"
  elsif @bytes < 1024 * 1024 * 1024
    "#{(@bytes / (1024 * 1024)).round}MB"
  else
    "#{(@bytes / (1024 * 1024 * 1024)).round}GB"
  end
end