Class: VirtualBox::GuestControl::UsbDevice

Inherits:
Object
  • Object
show all
Includes:
ActiveSupport::Configurable
Defined in:
lib/virtualbox/guest_control/usb_device.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uuid) ⇒ UsbDevice

Returns a new instance of UsbDevice.



46
47
48
# File 'lib/virtualbox/guest_control/usb_device.rb', line 46

def initialize(uuid)
  self.uuid = uuid
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



42
43
44
# File 'lib/virtualbox/guest_control/usb_device.rb', line 42

def address
  @address
end

#current_stateObject

Returns the value of attribute current_state.



42
43
44
# File 'lib/virtualbox/guest_control/usb_device.rb', line 42

def current_state
  @current_state
end

#manufacturerObject

Returns the value of attribute manufacturer.



42
43
44
# File 'lib/virtualbox/guest_control/usb_device.rb', line 42

def manufacturer
  @manufacturer
end

#portObject

Returns the value of attribute port.



42
43
44
# File 'lib/virtualbox/guest_control/usb_device.rb', line 42

def port
  @port
end

#productObject

Returns the value of attribute product.



42
43
44
# File 'lib/virtualbox/guest_control/usb_device.rb', line 42

def product
  @product
end

#product_idObject

Returns the value of attribute product_id.



41
42
43
# File 'lib/virtualbox/guest_control/usb_device.rb', line 41

def product_id
  @product_id
end

#revisionObject

Returns the value of attribute revision.



41
42
43
# File 'lib/virtualbox/guest_control/usb_device.rb', line 41

def revision
  @revision
end

#serial_numberObject

Returns the value of attribute serial_number.



43
44
45
# File 'lib/virtualbox/guest_control/usb_device.rb', line 43

def serial_number
  @serial_number
end

#uuidObject

Returns the value of attribute uuid.



41
42
43
# File 'lib/virtualbox/guest_control/usb_device.rb', line 41

def uuid
  @uuid
end

#vbox_manageObject

Returns the value of attribute vbox_manage.



44
45
46
# File 'lib/virtualbox/guest_control/usb_device.rb', line 44

def vbox_manage
  @vbox_manage
end

#vendor_idObject

Returns the value of attribute vendor_id.



41
42
43
# File 'lib/virtualbox/guest_control/usb_device.rb', line 41

def vendor_id
  @vendor_id
end

Class Method Details

.all(vbox_manage) ⇒ Object



7
8
9
10
# File 'lib/virtualbox/guest_control/usb_device.rb', line 7

def all(vbox_manage)
  result = Shellter.run!(vbox_manage, "list", "usbhost")
  parse(result.stdout)
end

.parse(output) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/virtualbox/guest_control/usb_device.rb', line 12

def parse(output)
  [].tap do |devices|
    device = nil
    output.lines.each do |line|
      if device
        if line.strip.blank?
          devices << device
          device = nil
        else
          key, value = line.split(":")
          key = key.strip.gsub(" ", "_").underscore
          value = value.strip
          begin
            device.send(:"#{key}=", value)
          rescue
            # this is the version/speed attribute... maybe we should parse it
            #puts [key, value].join(" => ")
          end
        end
      else
        next unless line =~ /UUID:/
        value = line.split(":").last.strip
        device = new(value)
      end
    end
  end
end

Instance Method Details

#stateObject



54
55
56
# File 'lib/virtualbox/guest_control/usb_device.rb', line 54

def state
  current_state
end

#to_sObject



50
51
52
# File 'lib/virtualbox/guest_control/usb_device.rb', line 50

def to_s
  "#{product} (#{uuid}): #{current_state}"
end