Refactor the nesting out of couchdb reduce and into ruby