Skip to content

Instantly share code, notes, and snippets.

@Unkas82
Created November 7, 2016 10:11
Show Gist options
  • Select an option

  • Save Unkas82/e0dd6b5595311ec07802e7f53532c0ef to your computer and use it in GitHub Desktop.

Select an option

Save Unkas82/e0dd6b5595311ec07802e7f53532c0ef to your computer and use it in GitHub Desktop.
def svernut dimensions, resources
gruppen = self.group_by{|e|[ dimensions.map{|dim| e.send(dim)} ]}
output_array = []
gruppen.each do |row|
row_hash = Hash.new(0)
dimensions.map{|dim| row_hash[dim] = row.second.first.send(dim) }
row.second.each do |elem|
resources.each do |res|
row_hash[res] += elem.send(res)
end
end
output_array << row_hash
end
output_array
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment