Class: Listing
- Inherits:
-
Object
- Object
- Listing
- Defined in:
- lib/Rubbit/Rubbit_Objects.rb
Instance Method Summary collapse
-
#initialize(json) ⇒ Listing
constructor
A new instance of Listing.
Constructor Details
#initialize(json) ⇒ Listing
Returns a new instance of Listing.
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
# File 'lib/Rubbit/Rubbit_Objects.rb', line 276 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| 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)] end end @children = children_objects end end |