Skip to content

Instantly share code, notes, and snippets.

@darkofabijan
Created September 27, 2010 13:58
Show Gist options
  • Save darkofabijan/599067 to your computer and use it in GitHub Desktop.
Save darkofabijan/599067 to your computer and use it in GitHub Desktop.
class Longtail
attr_accessor :model
attr_accessor :field
def initialize(options)
@model = options[:model]
@field = options[:field]
end
def fetch
data = @model.count(:group => @field, :order => "count_all DESC")
data.to_a.collect { |set| [set.second] }.to_json
end
end
class AnalyticsBase
attr_accessor :longtail_graphs
def initialize
@longtail_graphs = []
end
def register_longtail_graph(options)
@longtail_graphs << Longtail.new(options)
end
end
class Analytics < AnalyticsBase
register_longtail_graph :model => Design, :field => 'label_id'
register_longtail_graph :model => HeartVote, :field => 'user_id'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment