Class: Memory::Status

Inherits:
Struct
  • Object
show all
Defined in:
lib/memory_status.rb,
lib/memory_status.rb

Constant Summary collapse

Header =
members.map {|k| k.to_s.upcase.rjust(6)}.join('')
Format =
"%6d"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStatus

Returns a new instance of Status.



124
125
126
# File 'lib/memory_status.rb', line 124

def initialize
  _update
end

Class Method Details

.parse(str) ⇒ Object



135
136
137
138
139
140
141
# File 'lib/memory_status.rb', line 135

def self.parse(str)
  status = allocate
  str.scan(/(?:\A\{|\G,)(#{members.join('|')}):(\d+)(?=,|\}\z)/) do
    status[$1] = $2.to_i
  end
  status
end

Instance Method Details

#_updateObject



114
115
116
117
118
119
# File 'lib/memory_status.rb', line 114

def _update
  Memory.read_status do |key, val|
    self[key] = val
  end
  self
end

#to_sObject



128
129
130
131
132
133
# File 'lib/memory_status.rb', line 128

def to_s
  status = each_pair.map {|n,v|
    "#{n}:#{v}"
  }
  "{#{status.join(",")}}"
end