Transform an ActiveRecord-ish data set into pivot table