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

#initializenil



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

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:



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

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



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

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:



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

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