123456789_123456789_123456789_123456789_123456789_

Class: FFI::Enums

Relationships & Source Files
Inherits: Object
Defined in: lib/ffi/enum.rb

Overview

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

Class Method Summary

Instance Method Summary

Constructor Details

.newEnums

[ GitHub ]

  
# 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)

Add an Enum to the collection.

Parameters:

[ GitHub ]

  
# 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

Parameters:

  • symbol

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

Returns:

  • a symbol

[ GitHub ]

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

def __map_symbol(symbol)
  @symbol_map[symbol]
end

#find(query) ⇒ Enum

Find a Enum in collection.

Parameters:

  • query

    enum tag or part of an enum name

[ GitHub ]

  
# 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