class GeektoolKit::MemRecord
Constants
- BYTES_IN_A_MEG
Attributes
bytes[RW]
name[RW]
Public Class Methods
get_data()
click to toggle source
# File lib/geektool_kit/mem_record.rb, line 29 def self.get_data `ps -arcwwwxo "command rss" -m` end
get_records()
click to toggle source
# File lib/geektool_kit/mem_record.rb, line 33 def self.get_records data = self.get_data.encode("UTF-8", "binary", :invalid => :replace, :undef => :replace, :replace => "#").split("\n") records = [] data.each do |d| matches = /(?<name>.*)\s(?<bytes>\d+)/.match(d) records << MemRecord.new(matches) unless matches.nil? end return records end
new(line)
click to toggle source
# File lib/geektool_kit/mem_record.rb, line 12 def initialize line self.name = line[:name].strip self.bytes = line[:bytes].to_i * 1024 end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/geektool_kit/mem_record.rb, line 17 def <=> other return other.bytes <=> self.bytes end
create_display_text(max_width = 30)
click to toggle source
# File lib/geektool_kit/mem_record.rb, line 25 def create_display_text max_width = 30 create_line name, create_memory_display_text, max_width end
create_memory_display_text(precision = 2)
click to toggle source
# File lib/geektool_kit/mem_record.rb, line 21 def create_memory_display_text precision = 2 get_display_value(precision) + get_display_unit end
Private Instance Methods
get_display_unit()
click to toggle source
# File lib/geektool_kit/mem_record.rb, line 48 def get_display_unit bytes / BYTES_IN_A_MEG >= 1024 ? "G" : "M" end
get_display_value(precision = 2)
click to toggle source
# File lib/geektool_kit/mem_record.rb, line 52 def get_display_value precision = 2 result = bytes.to_f / BYTES_IN_A_MEG if (result >= 1024) result /= 1024 end "%.#{precision}f" % result end