Class: VpsbClient::Builders::MemoryParser
- Inherits:
-
SystemInfoParser
- Object
- SystemInfoParser
- VpsbClient::Builders::MemoryParser
- 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
-
#free ⇒ Object
readonly
Returns the value of attribute free.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
-
#used ⇒ Object
readonly
Returns the value of attribute used.
Instance Method Summary collapse
-
#initialize ⇒ MemoryParser
constructor
A new instance of MemoryParser.
- #parse ⇒ Object
Methods inherited from SystemInfoParser
#find_matches, #find_matches!, #lines
Constructor Details
#initialize ⇒ MemoryParser
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
#free ⇒ Object (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 |
#total ⇒ Object (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 |
#used ⇒ Object (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
#parse ⇒ Object
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 |