Class: GirFFI::ArrayElementConvertor

Inherits:
Object
  • Object
show all
Defined in:
lib/gir_ffi/array_element_convertor.rb

Overview

The ArrayElementConvertor class handles conversion from C array elements to ruby values

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, ptr) ⇒ ArrayElementConvertor

Returns a new instance of ArrayElementConvertor.



9
10
11
12
# File 'lib/gir_ffi/array_element_convertor.rb', line 9

def initialize(type, ptr)
  @value_type = type
  @pointer = ptr
end

Instance Attribute Details

#pointerObject (readonly)

Returns the value of attribute pointer.



7
8
9
# File 'lib/gir_ffi/array_element_convertor.rb', line 7

def pointer
  @pointer
end

#value_typeObject (readonly)

Returns the value of attribute value_type.



7
8
9
# File 'lib/gir_ffi/array_element_convertor.rb', line 7

def value_type
  @value_type
end

Instance Method Details

#to_ruby_valueObject



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/gir_ffi/array_element_convertor.rb', line 14

def to_ruby_value
  bare_value = to_value
  case value_type
  when :utf8, :filename
    bare_value.to_utf8
  when Array
    value_type[1].wrap bare_value
  when Module
    value_type.wrap bare_value
  else
    bare_value
  end
end