class Hash # creates a uniq sha1 digest of the hash's values # should mirror similar code in OneBody's lib/db_tools.rb def values_for_hash(*attrs) attrs = keys.sort unless attrs.any? attrs = attrs.first if attrs.first.is_a?(Array) values = attrs.map do |attr| value = self[attr.to_s] if value.respond_to?(:strftime) value.strftime('%Y-%m-%d %H:%M:%S') elsif value == true 1 elsif value == false 0 else value end end end def values_hash(*attrs) Digest::SHA1.hexdigest(values_for_hash(*attrs).join) end end