Class: PS

Inherits:
Object
  • Object
show all
Includes:
RunCommand
Defined in:
lib/city_watch/commands/ps.rb

Instance Method Summary collapse

Methods included from RunCommand

#command_line, #command_output, included, #options, #set_opts, #supported?

Instance Method Details

#command_line_optsObject



7
8
9
# File 'lib/city_watch/commands/ps.rb', line 7

def command_line_opts
  "aux"
end

#dataObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/city_watch/commands/ps.rb', line 11

def data
  headers = false
  command_output.split("\n").map {|line| line.split("\s") }.inject([]) do |output,line|
    if !headers
      headers = line.map {|hdr| hdr.downcase.to_sym}
    else
      pkt = {}
      cmd = line.slice!(10,line.size-1)
      line << cmd.join(" ")
      line.each_with_index do |itm,idx|
        pkt[headers[idx]] = itm
      end
      output << pkt
    end
    output
  end
end