Class: Listing

Inherits:
Object
  • Object
show all
Defined in:
lib/Rubbit/Rubbit_Objects.rb

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ Listing

Returns a new instance of Listing.



248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/Rubbit/Rubbit_Objects.rb', line 248

def initialize(json)
	if(json['kind']=='Listing')
		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|
			case c['kind']
			when 't1'
				children_objects += [Comment.new(c)]
			when 't2'
				children_objects += [Redditor.new(c)]
			when 't3'
				children_objects += [Post.new(c)]
			when 't4'
				children_objects += [Message.new(c)]
			when 't5'
				children_objects += [Subreddit.new(c)]
			when 'Listing'
				children_objects += [Listing.new(c)]
			end
		end
		@children = children_objects
	end
end