Class: FFI::Enum
- Inherits:
-
Type
- Object
- Type
- FFI::Enum
- Defined in:
- lib/ffi/enum.rb,
ext/ffi_c/Type.c
Instance Attribute Summary collapse
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
Instance Method Summary collapse
- #[](query) ⇒ Object (also: #find)
-
#initialize(info, tag = nil) ⇒ Enum
constructor
A new instance of Enum.
- #symbol_map ⇒ Object (also: #to_h)
- #symbols ⇒ Object
Constructor Details
#initialize(info, tag = nil) ⇒ Enum
Returns a new instance of Enum.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/ffi/enum.rb', line 34 def initialize(info, tag=nil) @tag = tag @kv_map = Hash.new @vk_map = Hash.new unless info.nil? last_cst = nil value = 0 info.each do |i| case i when Symbol @kv_map[i] = value @vk_map[value] = i last_cst = i value += 1 when Integer @kv_map[last_cst] = i @vk_map[i] = last_cst value = i+1 end end end end |
Instance Attribute Details
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
32 33 34 |
# File 'lib/ffi/enum.rb', line 32 def tag @tag end |
Instance Method Details
#[](query) ⇒ Object Also known as: find
61 62 63 64 65 66 67 68 |
# File 'lib/ffi/enum.rb', line 61 def [](query) case query when Symbol @kv_map[query] when Integer @vk_map[query] end end |
#symbol_map ⇒ Object Also known as: to_h
71 72 73 |
# File 'lib/ffi/enum.rb', line 71 def symbol_map @kv_map end |
#symbols ⇒ Object
57 58 59 |
# File 'lib/ffi/enum.rb', line 57 def symbols @kv_map.keys end |