This method seems to work:
  def self.create_summary_row(array)
    unless array.blank?
      klazz = array.first.class
      sum_stat = klazz.new
      array.each do |line|
        if line.is_a?(klazz)
          line.attributes.each do |k,v|
            unless v.nil? || v.is_a?(Time) || v.is_a?(Date)
              if sum_stat[k].nil?
                sum_stat[k] = v 
              else
                sum_stat[k] += v
              end 
            end
          end
        end
      end
      sum_stat
    end
  end
 
No comments:
Post a Comment