Class: Mool::Memory

Inherits:
Base
  • Object
show all
Defined in:
lib/mool/memory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#attrs

Constructor Details

#initializeMemory

Returns a new instance of Memory.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/mool/memory.rb', line 6

def initialize
  Mool::Command.meminfo.scan(/(\S+):\s+(\d+)/).each do |meminfo|
    var = meminfo[0].tr('(', '_').tr(')', '').underscore
    instance_variable_set(
      "@#{var}",
      (meminfo[1].to_f * Mool::PARSE_TYPES[Mool::KBYTES]).round(2)
    )
    class_eval { attr_accessor var.to_sym }
  end
  @unity = Mool::BYTES
  @mem_used = @mem_total - (@mem_free +
                            @cached +
                            @buffers +
                            @swap_cached)
end

Instance Attribute Details

#mem_usedObject

Returns the value of attribute mem_used.



4
5
6
# File 'lib/mool/memory.rb', line 4

def mem_used
  @mem_used
end

#unityObject

Returns the value of attribute unity.



4
5
6
# File 'lib/mool/memory.rb', line 4

def unity
  @unity
end

Instance Method Details

#to_bObject



22
23
24
25
26
27
28
# File 'lib/mool/memory.rb', line 22

def to_b
  Mool.parse_to(
    self,
    (instance_variable_names - ["@unity"]),
    Mool::BYTES
  )
end

#to_gbObject



46
47
48
49
50
51
52
# File 'lib/mool/memory.rb', line 46

def to_gb
  Mool.parse_to(
    self,
    (instance_variable_names - ["@unity"]),
    Mool::GBYTES
  )
end

#to_kbObject



30
31
32
33
34
35
36
# File 'lib/mool/memory.rb', line 30

def to_kb
  Mool.parse_to(
    self,
    (instance_variable_names - ["@unity"]),
    Mool::KBYTES
  )
end

#to_mbObject



38
39
40
41
42
43
44
# File 'lib/mool/memory.rb', line 38

def to_mb
  Mool.parse_to(
    self,
    (instance_variable_names - ["@unity"]),
    Mool::MBYTES
  )
end