class GirFFI::Builders::CToRubyConvertor

Builder that generates code to convert values from C to Ruby. Used by argument builders.

Public Class Methods

new(type_info, argument_name, length_arg) click to toggle source
# File lib/gir_ffi/builders/c_to_ruby_convertor.rb, line 6
def initialize(type_info, argument_name, length_arg)
  @type_info = type_info
  @argument_name = argument_name
  @length_arg = length_arg
end

Public Instance Methods

conversion() click to toggle source
# File lib/gir_ffi/builders/c_to_ruby_convertor.rb, line 12
def conversion
  case @type_info.flattened_tag
  when :utf8, :filename
    "#{@argument_name}.to_utf8"
  else
    "#{@type_info.argument_class_name}.wrap(#{conversion_argument_list})"
  end
end

Private Instance Methods

array_size() click to toggle source
# File lib/gir_ffi/builders/c_to_ruby_convertor.rb, line 35
def array_size
  if @length_arg
    @length_arg
  else
    @type_info.array_fixed_size
  end
end
conversion_argument_list() click to toggle source
# File lib/gir_ffi/builders/c_to_ruby_convertor.rb, line 23
def conversion_argument_list
  conversion_arguments.join(', ')
end
conversion_arguments() click to toggle source
# File lib/gir_ffi/builders/c_to_ruby_convertor.rb, line 27
def conversion_arguments
  if @type_info.flattened_tag == :c
    [@type_info.element_type.inspect, array_size, @argument_name]
  else
    @type_info.extra_conversion_arguments.map(&:inspect).push(@argument_name)
  end
end