Class: Stats::TagCloudQuery
- Inherits:
-
Object
- Object
- Stats::TagCloudQuery
- Defined in:
- app/models/stats/tag_cloud_query.rb
Instance Attribute Summary collapse
-
#cutoff ⇒ Object
readonly
Returns the value of attribute cutoff.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
-
#initialize(user, cutoff = nil) ⇒ TagCloudQuery
constructor
A new instance of TagCloudQuery.
- #query_options ⇒ Object
- #result ⇒ Object
- #sql ⇒ Object
Constructor Details
#initialize(user, cutoff = nil) ⇒ TagCloudQuery
Returns a new instance of TagCloudQuery.
5 6 7 8 |
# File 'app/models/stats/tag_cloud_query.rb', line 5 def initialize(user, cutoff = nil) @user = user @cutoff = cutoff end |
Instance Attribute Details
#cutoff ⇒ Object (readonly)
Returns the value of attribute cutoff.
3 4 5 |
# File 'app/models/stats/tag_cloud_query.rb', line 3 def cutoff @cutoff end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
3 4 5 |
# File 'app/models/stats/tag_cloud_query.rb', line 3 def user @user end |
Instance Method Details
#query_options ⇒ Object
14 15 16 17 18 |
# File 'app/models/stats/tag_cloud_query.rb', line 14 def = [sql, user.id] += [cutoff, cutoff] if cutoff end |
#result ⇒ Object
10 11 12 |
# File 'app/models/stats/tag_cloud_query.rb', line 10 def result Tag.find_by_sql() end |
#sql ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/models/stats/tag_cloud_query.rb', line 20 def sql # TODO: parameterize limit query = "SELECT tags.id, tags.name AS name, COUNT(*) AS count" query << " FROM taggings, tags, todos" query << " WHERE tags.id = tag_id" query << " AND todos.user_id = ? " query << " AND taggings.taggable_type = 'Todo' " query << " AND taggings.taggable_id = todos.id " if cutoff query << " AND (todos.created_at > ? OR " query << " todos.completed_at > ?) " end query << " GROUP BY tags.id, tags.name" query << " ORDER BY count DESC, name " query << " LIMIT 100" end |