class GObjectIntrospection::TypeTag

Public Instance Methods

description(type_info) click to toggle source
# File lib/gobject-introspection/type-tag.rb, line 28
def description(type_info)
  method = "description_#{nick}"
  if respond_to?(method, true)
    __send__(method, type_info)
  else
    nick
  end
end
try_convert(type_info, value) click to toggle source
# File lib/gobject-introspection/type-tag.rb, line 19
def try_convert(type_info, value)
  method = "try_convert_#{nick}"
  if respond_to?(method, true)
    __send__(method, type_info, value)
  else
    nil
  end
end

Private Instance Methods

description_array(type_info)
description_array_like(type_info) click to toggle source
# File lib/gobject-introspection/type-tag.rb, line 127
def description_array_like(type_info)
  element_type_info = type_info.get_param_type(0)
  "#{nick}(#{element_type_info.description})"
end
description_ghash(type_info) click to toggle source
# File lib/gobject-introspection/type-tag.rb, line 165
def description_ghash(type_info)
  key_type = type_info.get_param_type(0)
  value_type = type_info.get_param_type(1)
  "#{nick}(#{key_type.description}->#{value_type.description})"
end
description_glist(type_info)
description_gslist(type_info)
description_interface(type_info) click to toggle source
# File lib/gobject-introspection/type-tag.rb, line 175
def description_interface(type_info)
  "#{nick}(#{type_info.interface.description})"
end
get_element_type_info(type_info) click to toggle source
# File lib/gobject-introspection/type-tag.rb, line 132
def get_element_type_info(type_info)
  type_info.get_param_type(0)
end
try_convert_array(type_info, value) click to toggle source
# File lib/gobject-introspection/type-tag.rb, line 136
def try_convert_array(type_info, value)
  case get_element_type_info(type_info).tag
  when INT8, UINT8
    case value
    when String
      return value
    when GLib::Bytes
      return value.to_s
    end
  end
  try_convert_array_like(type_info, value)
end
try_convert_array_like(type_info, value) click to toggle source
# File lib/gobject-introspection/type-tag.rb, line 114
def try_convert_array_like(type_info, value)
  value = Array.try_convert(value)
  return nil if value.nil?
  element_type_info = get_element_type_info(type_info)
  value.collect do |v|
    unless v.nil?
      v = element_type_info.try_convert(v)
      return nil if v.nil?
    end
    v
  end
end
try_convert_boolean(type_info, value) click to toggle source
# File lib/gobject-introspection/type-tag.rb, line 38
def try_convert_boolean(type_info, value)
  case value
  when true, false
    value
  when nil
    false
  else
    nil
  end
end
try_convert_double(type_info, value)
Alias for: try_convert_float
try_convert_filename(type_info, value) click to toggle source
# File lib/gobject-introspection/type-tag.rb, line 99
def try_convert_filename(type_info, value)
  case value
  when String
    value.encode(GLib::FILENAME_ENCODING)
  else
    if value.respond_to?(:to_path)
      value.to_path.encode(GLib::FILENAME_ENCODING)
    elsif value.respond_to?(:to_str)
      value.to_str.encode(GLib::FILENAME_ENCODING)
    else
      nil
    end
  end
end
try_convert_float(type_info, value) click to toggle source
# File lib/gobject-introspection/type-tag.rb, line 68
def try_convert_float(type_info, value)
  if value.is_a?(Float)
    value
  elsif value.respond_to?(:to_f) # TODO: Should we stop this?
    value.to_f
  else
    nil
  end
end
Also aliased as: try_convert_double
try_convert_ghash(type_info, value) click to toggle source
# File lib/gobject-introspection/type-tag.rb, line 156
def try_convert_ghash(type_info, value)
  case value
  when Hash
    value
  else
    nil
  end
end
try_convert_glist(type_info, value)
try_convert_gslist(type_info, value)
try_convert_gtype(type_info, value) click to toggle source
# File lib/gobject-introspection/type-tag.rb, line 80
def try_convert_gtype(type_info, value)
  GLib::Type.try_convert(value)
end
try_convert_int16(type_info, value)
Alias for: try_convert_integer
try_convert_int32(type_info, value)
Alias for: try_convert_integer
try_convert_int64(type_info, value)
Alias for: try_convert_integer
try_convert_int8(type_info, value)
Alias for: try_convert_integer
try_convert_integer(type_info, value) click to toggle source
# File lib/gobject-introspection/type-tag.rb, line 49
def try_convert_integer(type_info, value)
  if value.is_a?(Integer)
    value
  elsif value.respond_to?(:to_int)
    value.to_int
  else
    nil
  end
end
try_convert_interface(type_info, value) click to toggle source
# File lib/gobject-introspection/type-tag.rb, line 171
def try_convert_interface(type_info, value)
  type_info.interface.try_convert(value)
end
try_convert_uint16(type_info, value)
Alias for: try_convert_integer
try_convert_uint32(type_info, value)
Alias for: try_convert_integer
try_convert_uint64(type_info, value)
Alias for: try_convert_integer
try_convert_uint8(type_info, value)
Alias for: try_convert_integer
try_convert_utf8(type_info, value) click to toggle source
# File lib/gobject-introspection/type-tag.rb, line 84
def try_convert_utf8(type_info, value)
  case value
  when String
    value.encode(Encoding::UTF_8)
  when Symbol
    value.to_s.encode(Encoding::UTF_8)
  else
    if value.respond_to?(:to_str)
      value.to_str.encode(Encoding::UTF_8)
    else
      nil
    end
  end
end