Skip to content

Instantly share code, notes, and snippets.

@JakubOboza
Created August 16, 2012 13:47
Show Gist options
  • Save JakubOboza/3370203 to your computer and use it in GitHub Desktop.
Save JakubOboza/3370203 to your computer and use it in GitHub Desktop.
module Presenters
class SitesPieChart
attr_accessor :overall_data, :current_month_data, :objects
def initialize(objects)
self.objects = objects
end
def overall
self.overall_data ||= self.objects.map do |site|
{:label => site.name,
:data => Stats::CallCounter.new(site).overall.to_i}
end
self.overall_data
end
def current_month
self.current_month_data ||= self.objects.map do |site|
{:label => site.name,
:data => Stats::CallCounter.new(site).current_month.to_i}
end
self.current_month_data
end
def show(time_scope = :overall)
result = case time_scope.to_sym
when :overall then
self.overall
when :current_month
self.current_month
end
result.to_json
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment