From 8b4ddbb23072b13206fdfd6a2c2581c8c5fe6274 Mon Sep 17 00:00:00 2001 From: Gregor Schmidt Date: Fri, 21 Jan 2011 16:19:10 +0100 Subject: [PATCH] Improving Report#hash to be semantically more useful --- lib/report.rb | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/report.rb b/lib/report.rb index b833c7fbb5..978eb108f6 100644 --- a/lib/report.rb +++ b/lib/report.rb @@ -135,13 +135,23 @@ class Report < ActiveRecord::Base end def hash - filter_string = filters.inject("") do |str, f| - str + f.class.underscore_name + f.operator.to_s + (f.values ? f.values.to_json : "") - end - filter_string = group_bys.collect(&:class).sort_by(&:underscore_name).inject(filter_string) do |string, gb| - string.concat(gb.underscore_name) - end - filter_string.hash + report_string = "" + + report_string.concat('filters: [') + report_string.concat(filters.map { |f| + f.class.underscore_name + f.operator.to_s + (f.values ? f.values.to_json : "") + }.sort.join(', ')) + report_string.concat(']') + + report_string.concat(', group_bys: {') + + report_string.concat(group_bys.group_by(&:type).map { |t, gbs| + "#{t} : [#{gbs.collect(&:class).collect(&:underscore_name).join(', ')}]" + }.join(', ')) + + report_string.concat('}') + + report_string.hash end def == another_report @@ -153,5 +163,4 @@ class Report < ActiveRecord::Base def minimal_chain! @chain = self.class::Filter::NoFilter.new end - end