class Listing

Public Class Methods

new(json) click to toggle source
# File lib/Rubbit/Rubbit_Objects.rb, line 718
def initialize(json)
        if(json['kind']=='Listing' or json['kind']=='UserList')
                @after = nil
                data = json['data']
                data.each_key do |k|
                        self.class.module_eval {attr_accessor(k)}
                        self.send("#{k}=",data[k])
                end
                children_objects = []
                @children.each do |c|
                        if(c['id']==nil)
                                c['id']='   '
                        end
                        if(c['kind'] == 't1' or c['id'][0..2]=='t1_')
                                children_objects += [Comment.new(c)]
                        elsif(c['kind'] == 't2' or c['id'][0..2]=='t2_')
                                children_objects += [Redditor.new(c)]
                        elsif(c['kind'] == 't3' or c['id'][0..2]=='t3_')
                                children_objects += [Post.new(c)]
                        elsif(c['kind'] == 't4' or c['id'][0..2]=='t4_')
                                children_objects += [Message.new(c)]
                        elsif(c['kind'] == 't5' or c['id'][0..2]=='t5_')
                                children_objects += [Subreddit.new(c)]
                        elsif(c['kind'] == 'Listing')
                                children_objects += [Listing.new(c)]
                        elsif(c['kind'] == 'LiveUpdate')
                                children_objects += [Live_Update.new(c)]
                        end
                end
                @children = children_objects
        end
end