Sha256: 902c0340dfa3029f45f589fdb06cbcafe1f0833a823281b4c36d55cd65a46e2a

Contents?: true

Size: 1.02 KB

Versions: 11

Compression:

Stored size: 1.02 KB

Contents

module GObjectIntrospection
  # Wraps a GIConstantInfo struct; represents a constant.
  class IConstantInfo < IBaseInfo
    TYPE_TAG_TO_UNION_MEMBER = {
      gboolean: :v_boolean,
      gint8:    :v_int8,
      gint16:   :v_int16,
      gint32:   :v_int32,
      gint64:   :v_int64,
      guint8:   :v_uint8,
      guint16:  :v_uint16,
      guint32:  :v_uint32,
      guint64:  :v_uint64,
      gdouble:  :v_double,
      utf8:     :v_string
    }

    def value
      case type_tag
      when :utf8
        raw_value.force_encoding('utf-8')
      when :gboolean
        raw_value != 0
      else
        raw_value
      end
    end

    def constant_type
      ITypeInfo.wrap(Lib.g_constant_info_get_type @gobj)
    end

    private

    def type_tag
      @type_tag ||= constant_type.tag
    end

    def raw_value
      value_union = Lib::GIArgument.new
      Lib.g_constant_info_get_value @gobj, value_union
      value_union[union_member_key]
    end

    def union_member_key
      TYPE_TAG_TO_UNION_MEMBER[type_tag]
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
gir_ffi-0.9.0 lib/ffi-gobject_introspection/i_constant_info.rb
gir_ffi-0.8.6 lib/ffi-gobject_introspection/i_constant_info.rb
gir_ffi-0.8.5 lib/ffi-gobject_introspection/i_constant_info.rb
gir_ffi-0.8.4 lib/ffi-gobject_introspection/i_constant_info.rb
gir_ffi-0.8.3 lib/ffi-gobject_introspection/i_constant_info.rb
gir_ffi-0.8.2 lib/ffi-gobject_introspection/i_constant_info.rb
gir_ffi-0.8.1 lib/ffi-gobject_introspection/i_constant_info.rb
gir_ffi-0.8.0 lib/ffi-gobject_introspection/i_constant_info.rb
gir_ffi-0.7.10 lib/ffi-gobject_introspection/i_constant_info.rb
gir_ffi-0.7.9 lib/ffi-gobject_introspection/i_constant_info.rb
gir_ffi-0.7.8 lib/ffi-gobject_introspection/i_constant_info.rb