Class: FFI::Enums

Inherits:
Object
  • Object
show all
Defined in:
lib/ffi/enum.rb

Overview

An instance of this class permits to manage Enums. In fact, Enums is a collection of Enums.

Instance Method Summary collapse

Constructor Details

#initializeEnums

Returns a new instance of Enums.



38
39
40
41
42
# File 'lib/ffi/enum.rb', line 38

def initialize
  @all_enums = Array.new
  @tagged_enums = Hash.new
  @symbol_map = Hash.new
end

Instance Method Details

#<<(enum) ⇒ Object

Add an FFI::Enum to the collection.

Parameters:



46
47
48
49
50
# File 'lib/ffi/enum.rb', line 46

def <<(enum)
  @all_enums << enum
  @tagged_enums[enum.tag] = enum unless enum.tag.nil?
  @symbol_map.merge!(enum.symbol_map)
end

#__map_symbol(symbol) ⇒ Object

Returns a symbol.

Parameters:

  • symbol

    a symbol to find in merge symbol maps of all enums.

Returns:

  • a symbol



65
66
67
# File 'lib/ffi/enum.rb', line 65

def __map_symbol(symbol)
  @symbol_map[symbol]
end

#find(query) ⇒ Enum

Find a FFI::Enum in collection.

Parameters:

  • query

    enum tag or part of an enum name

Returns:



55
56
57
58
59
60
61
# File 'lib/ffi/enum.rb', line 55

def find(query)
  if @tagged_enums.has_key?(query)
    @tagged_enums[query]
  else
    @all_enums.detect { |enum| enum.symbols.include?(query) }
  end
end