class FFI::Enums

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

Public Class Methods

new() click to toggle source

@return [nil]

# File lib/ffi/enum.rb, line 39
def initialize
  @all_enums = Array.new
  @tagged_enums = Hash.new
  @symbol_map = Hash.new
end

Public Instance Methods

<<(enum) click to toggle source

@param [Enum] enum Add an {Enum} to the collection.

# 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) click to toggle source

@param symbol a symbol to find in merge symbol maps of all enums. @return a symbol

# File lib/ffi/enum.rb, line 66
def __map_symbol(symbol)
  @symbol_map[symbol]
end
find(query) click to toggle source

@param query enum tag or part of an enum name @return [Enum] Find a {Enum} in collection.

# 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