5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/dockage/docker/parse.rb', line 5
def parse_docker_ps(string)
= string.shift
spaces = column_width = 0
keys = {}
.chars.each_with_index do |char, i|
if i == (.size - 1) || (char !~ /\s/ && spaces > 1)
keys.merge!(slice_column_from_string(, i, column_width))
column_width = 0
end
spaces = char =~ /\s/ ? spaces + 1 : 0
column_width += 1
end
string.map do |container_string|
container = Hash[keys.map { |k, v| [k, container_string[v[:start]..v[:stop]].strip] }]
container[:names] = container[:names].to_s.split(',')
container[:name] = container[:names].reject{ |v| v.include?('/') }.first
container[:linked_with] = container[:names].map{ |name| name.split('/')[0] }.compact
container[:running] = container[:status].downcase
.include?('up') ? true : false
container
end
end
|