Method: VirtualBox::Vm.parse_machine_readable

Defined in:
lib/virtual_box/vm.rb

.parse_machine_readable(output) ⇒ Hash<String, Object>

Parses the output of the ‘VBoxManage showvminfo –machinereadable’ command.

Parameters:

  • output (String)

    the command output

Returns:

  • (Hash<String, Object>)

    a Hash whose keys are the strings on the left side of “=” on each line, and whose values are the strings on the right side



290
291
292
293
294
295
296
297
# File 'lib/virtual_box/vm.rb', line 290

def self.parse_machine_readable(output)
  Hash[output.split("\n").map { |line|
    key, value = *line.split('=', 2)
    key = key[1...-1] if key[0] == ?"  # Remove string quotes ("").
    value = value[1...-1] if value[0] == ?"  # Remove string quotes ("").
    [key, value]
  }]    
end