i made you this:


selects = ["Here", "There"]

data = [
  [ 'Ref', 'Count', 'Locn' ],
  [ 'Part1', '3', 'Here' ],
  [ 'Part2', '1', 'Here' ],
  [ 'Part1', '2', 'There' ],
]


data[1..-1].group_by(&:first).map {|k,d|
[k,d.inject(0){|s,v|s+v[1].to_i}] + selects.map {|s| 
d.select{|v|v[2]==s}.inject(0){|s,v|s+v[1].to_i} }
}

#=> [["Part1", 5, 3, 2], ["Part2", 1, 1, 0]]

-- 
Posted via http://www.ruby-forum.com/.