lib/rpm/package.rb
def [](tag)
      val = nil
      tagc = ::FFI::AutoPointer.new(RPM::C.rpmtdNew, Package.method(:release_td))

      return nil if RPM::C.headerGet(ptr, tag, tagc,
                                     RPM::C::HEADERGET_MINMEM) == 0

      type = RPM::C.rpmtdType(tagc)
      count = RPM::C.rpmtdCount(tagc)
      ret_type = RPM::C.rpmTagGetReturnType(tag)

      method_name = case type
                    when :int8_type, :char_type, :int16_type, :int32_type, :int64_type then :rpmtdGetNumber
                    when :string_type, :string_array_type, :bin_type then :rpmtdGetString
                    else raise NotImplementedError, "Don't know how to retrieve type '#{type}'"
                    end

      is_array = if count > 1 then true
                 elsif ret_type == :array_return_type then true
                 elsif type == :string_array_type then true
                 else false
                 end

      if is_array
        ret = []
        RPM::C.rpmtdInit(tagc)
        ret << RPM::C.send(method_name, tagc) while RPM::C.rpmtdNext(tagc) != -1
        return ret
      end

      RPM::C.send(method_name, tagc)
    end
def [](tag)
      val = nil
      tagc = ::FFI::AutoPointer.new(RPM::C.rpmtdNew, Package.method(:release_td))

      return nil if RPM::C.headerGet(ptr, tag, tagc,
                                     RPM::C::HEADERGET_MINMEM) == 0

      type = RPM::C.rpmtdType(tagc)
      count = RPM::C.rpmtdCount(tagc)
      ret_type = RPM::C.rpmTagGetReturnType(tag)

      method_name = case type
                    when :int8_type, :char_type, :int16_type, :int32_type, :int64_type then :rpmtdGetNumber
                    when :string_type, :string_array_type, :bin_type then :rpmtdGetString
                    else raise NotImplementedError, "Don't know how to retrieve type '#{type}'"
                    end

      is_array = if count > 1 then true
                 elsif ret_type == :array_return_type then true
                 elsif type == :string_array_type then true
                 else false
                 end

      if is_array
        ret = []
        RPM::C.rpmtdInit(tagc)
        ret << RPM::C.send(method_name, tagc) while RPM::C.rpmtdNext(tagc) != -1
        return ret
      end

      RPM::C.send(method_name, tagc)
    end
Access a header entry
 @param [Number] tag Tag to return
 @return [] Value of the entry
 @example
     pkg => #<RPM::Package name="xmlgraphics-fop", version=#<RPM::Version v="1.0", r="22.4">>
     pkg[:name] => "xmlgraphics-fop"

   or if you have the old ruby-rpm compat loaded

     require 'rpm/compat'
     pkg[RPM::TAG_NAME] => "xmlgraphics-fop"

 @return [String, Fixnum, Array<String>, Array<Fixnum>, nil]
   The value of the entry