diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 9282420..09e9aca 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,27 +1,20 @@ module ApplicationHelper - - - def message_graph(problem) create_percentage_table_for(problem) {|notice| notice.message} end - - - + def user_agent_graph(problem) create_percentage_table_for(problem) {|notice| pretty_user_agent(notice.user_agent)} end - + def pretty_user_agent(user_agent) (user_agent.nil? || user_agent.none?) ? "N/A" : "#{user_agent.browser} #{user_agent.version}" end - - - + def tenant_graph(problem) create_percentage_table_for(problem) {|notice| get_host(notice.request['url'])} end - + def get_host(url) begin uri = url && URI.parse(url) @@ -30,14 +23,13 @@ module ApplicationHelper "N/A" end end - - - + + def create_percentage_table_for(problem, &block) tallies = tally(problem.notices, &block) create_percentage_table_from_tallies(tallies, :total => problem.notices.count) end - + def tally(collection, &block) collection.inject({}) do |tallies, item| value = yield item @@ -45,7 +37,7 @@ module ApplicationHelper tallies end end - + def create_percentage_table_from_tallies(tallies, options={}) total = (options[:total] || total_from_tallies(tallies)) percent = 100.0 / total.to_f @@ -53,13 +45,10 @@ module ApplicationHelper .sort {|a, b| a[0] <=> b[0]} render :partial => "errs/tally_table", :locals => {:rows => rows} end - - - def total_from_tallies(tallies) - tallies.values.inject(0) {|sum, n| sum + n} - end - private :total_from_tallies - - + + private + def total_from_tallies(tallies) + tallies.values.inject(0) {|sum, n| sum + n} + end end -- libgit2 0.21.2