this looks like an excellent candidate for `group_by` http://api.rubyonrails.org/classes/Enumerable.html#method-i-group_by