I am working on a script that collects all comments from my DB and inserts them into a hash. I then do a collect on the comments hash and split the comments into two separate comment hashes (vid_comments & wall_comments)
w_hash = Hash.new
w_hash["comments"] = []
contender.subscriber.videos.collect { |v| w_hash["comments"] << v.comments.where("created_at > DATE_SUB( NOW(), INTERVAL 1 DAY)") }
w_hash["comments"] << contender.profile.comments.where("created_at > DATE_SUB( NOW(), INTERVAL 1 DAY)")
w_hash["comments"].delete_if { |x| x.blank? }
w_hash["vid_comments"] = w_hash["comments"].collect { |c| !c.media_id.nil? }
w_hash["wall_comments"] = w_hash["comments"].collect { |w| w.parent_id == 0 }
w_hash.delete("comments")
Is there anyway to shorten the code? I am pretty new to Ruby (PHP import) so excuse my ignorance in things I may be doing wrong.