Class: VirtualBox::COM::AbstractEnum

Inherits:
AbstractModel show all
Extended by:
Enumerable
Defined in:
lib/virtualbox/com/abstract_enum.rb

Overview

Represents a C enum type. Provides functionality to easily convert an int value to its proper symbol within the enum.

Direct Known Subclasses

Model::AccessMode, Model::AdditionsFacilityClass, Model::AdditionsFacilityStatus, Model::AdditionsFacilityType, Model::AdditionsRunLevelType, Model::AdditionsUpdateFlag, Model::AudioControllerType, Model::AudioDriverType, Model::AuthType, Model::AutostopType, Model::BIOSBootMenuMode, Model::BandwidthGroupType, Model::CPUPropertyType, Model::ChipsetType, Model::CleanupMode, Model::ClipboardMode, Model::CloneMode, Model::CloneOptions, Model::CopyFileFlag, Model::DataFlags, Model::DataType, Model::DeviceActivity, Model::DeviceType, Model::DirectoryCreateFlag, Model::DirectoryOpenFlag, Model::DirectoryRemoveRecFlag, Model::DragAndDropAction, Model::DragAndDropMode, Model::FaultToleranceState, Model::FileSeekType, Model::FirmwareType, Model::FramebufferPixelFormat, Model::FsObjType, Model::GuestMonitorChangedEventType, Model::HWVirtExPropertyType, Model::HostNetworkInterfaceMediumType, Model::HostNetworkInterfaceStatus, Model::HostNetworkInterfaceType, Model::ImportOptions, Model::KeyboardHIDType, Model::LockType, Model::MachineState, Model::MediumFormatCapabilities, Model::MediumState, Model::MediumType, Model::MediumVariant, Model::MouseButtonState, Model::NATAliasMode, Model::NATProtocol, Model::NetworkAdapterPromiscModePolicy, Model::NetworkAdapterType, Model::NetworkAttachmentType, Model::PathRenameFlag, Model::PointingHIDType, Model::PortMode, Model::ProcessCreateFlag, Model::ProcessInputFlag, Model::ProcessOutputFlag, Model::ProcessPriority, Model::ProcessStatus, Model::ProcessWaitForFlag, Model::ProcessWaitResult, Model::ProcessorFeature, Model::Scope, Model::SessionState, Model::SessionType, Model::SettingsVersion, Model::StorageBus, Model::StorageControllerType, Model::SymlinkReadFlag, Model::SymlinkType, Model::USBDeviceFilterAction, Model::USBDeviceState, Model::VBoxEventType, Model::VFSFileType, Model::VFSType, Model::VirtualSystemDescriptionType, Model::VirtualSystemDescriptionValueType

Class Method Summary collapse

Methods inherited from AbstractModel

iid, setup

Class Method Details

.[](index) ⇒ Object

Returns the symbol associated with the given key



30
31
32
33
34
35
# File 'lib/virtualbox/com/abstract_enum.rb', line 30

def self.[](index)
    case index
    when Symbol then @map[index]
    else             @reverse_map[index]
    end
end

.eachObject

Iterate over the enum, yielding each item to a block.



43
44
45
46
47
# File 'lib/virtualbox/com/abstract_enum.rb', line 43

def self.each
    @map.each do |key, value|
        yield key
    end
end

.index(key) ⇒ Object

Returns the index associated with a value



38
39
40
# File 'lib/virtualbox/com/abstract_enum.rb', line 38

def self.index(key)
    @map[key]
end

.map(value = nil) ⇒ Object

Defines the mapping of int => symbol for the given Enum. The parameter to this can be an Array or Hash or anything which respond to ‘each` and yield a key/value pair. If a value appear more than once, only the first is kept If value is left nil, it will return the current mapping



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/virtualbox/com/abstract_enum.rb', line 16

def self.map(value = nil)
    if value
        m, r = {}, {}
        if Array === value
        then value.each_index {|i|   m[value[i]] = i; r[i] = value[i] }
        else value.each       {|k,v| m[k] = v;        r[v] ||= k      }
        end            
        @map, @reverse_map = m, r
    end
    
    @map
end