lib/tdlib/types.rb
# Recursively wraps a hash into typed classes
Recursively wraps a hash into typed classes
Recursively wraps a hash into typed classes
def wrap(object)
    if object.kind_of?(::Array)
      object.map { |o| wrap(o) }
    elsif object.kind_of?(::Hash)
      type = object.delete('@type')
      object.each do |key, val|
        if val.respond_to?(:each)
          object[key] = wrap(val)
        end
      end
      unless type
        return object
      end
      if (klass = LOOKUP_TABLE[type])
        const_get(klass).new(object)
      else
        puts "Can't find class for #{type}" 
      end
    else 
      object
    end
  end
def wrap ( object ) if object . kind_of? ( :: Array ) object . map { | o | wrap ( o ) } elsif object . kind_of? ( :: Hash ) type = object . delete ( '@type' ) object . each do | key , val | if val . respond_to? ( :each ) object [ key ] = wrap ( val ) end end unless type return object end if ( klass = LOOKUP_TABLE [ type ] ) const_get ( klass ) . new ( object ) else puts "Can't find class for #{type}" end else object end end
Recursively wraps a hash into typed classes
Recursively wraps a hash into typed classes
# Wrapping each entry in array #raise ArgumentError.new("Can't find class for #{type}")
object