Class: VpsbClient::Builders::MemoryParser

Inherits:
SystemInfoParser show all
Defined in:
lib/vpsb_client/builders/system_info_parser.rb

Constant Summary collapse

REGEX_CACHE =
'cache:\s+(?<used>\d+)\s+(?<free>\d+)$'
REGEX_AVAIL =
'^Mem:\s+\d+\s+(?<used>\d+)\s+\d+\s+\d+\s+\d+\s+(?<avail>\d+)'
REGEX_TOTAL =
'^Mem:\s+(?<total>\d+)'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from SystemInfoParser

#find_matches, #find_matches!, #lines

Constructor Details

#initializeMemoryParser

Returns a new instance of MemoryParser.



38
39
40
# File 'lib/vpsb_client/builders/system_info_parser.rb', line 38

def initialize
  super('free')
end

Instance Attribute Details

#freeObject (readonly)

Returns the value of attribute free.



32
33
34
# File 'lib/vpsb_client/builders/system_info_parser.rb', line 32

def free
  @free
end

#totalObject (readonly)

Returns the value of attribute total.



32
33
34
# File 'lib/vpsb_client/builders/system_info_parser.rb', line 32

def total
  @total
end

#usedObject (readonly)

Returns the value of attribute used.



32
33
34
# File 'lib/vpsb_client/builders/system_info_parser.rb', line 32

def used
  @used
end

Instance Method Details

#parseObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/vpsb_client/builders/system_info_parser.rb', line 42

def parse
  matches = find_matches(REGEX_CACHE)
  if matches
    @used = matches[:used].to_i
    @free = matches[:free].to_i
  elsif matches = find_matches(REGEX_AVAIL)
    @used = matches[:used].to_i
    @free = matches[:avail].to_i
  else
    raise NoMatchError, "No regex matches 'free' output"     
  end
  matches = find_matches!(REGEX_TOTAL)
  @total = matches[:total].to_i
end