Class: GeektoolKit::MemRecord

Inherits:
Object
  • Object
show all
Includes:
LineFormatter
Defined in:
lib/geektool_kit/mem_record.rb

Constant Summary collapse

BYTES_IN_A_MEG =
1048576

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from LineFormatter

#create_line

Constructor Details

#initialize(line) ⇒ MemRecord

Returns a new instance of MemRecord.



12
13
14
15
# 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

Instance Attribute Details

#bytesObject

Returns the value of attribute bytes.



10
11
12
# File 'lib/geektool_kit/mem_record.rb', line 10

def bytes
  @bytes
end

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/geektool_kit/mem_record.rb', line 9

def name
  @name
end

Class Method Details

.get_dataObject



29
30
31
# File 'lib/geektool_kit/mem_record.rb', line 29

def self.get_data
  `ps -arcwwwxo "command rss" -m`
end

.get_recordsObject



33
34
35
36
37
38
39
40
41
42
43
# 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

Instance Method Details

#<=>(other) ⇒ Object



17
18
19
# File 'lib/geektool_kit/mem_record.rb', line 17

def <=> other
  return other.bytes <=> self.bytes
end

#create_display_text(max_width = 30) ⇒ Object



25
26
27
# 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) ⇒ Object



21
22
23
# File 'lib/geektool_kit/mem_record.rb', line 21

def create_memory_display_text precision = 2
  get_display_value(precision) + get_display_unit
end