Class: PopularPosts

Inherits:
Object
  • Object
show all
Defined in:
app/services/popular_posts.rb

Overview

Getting popular posts

Class Method Summary collapse

Class Method Details

.month(count) ⇒ Object



21
22
23
# File 'app/services/popular_posts.rb', line 21

def self.month(count)
  Post.visible.where(post_type_id: post_type_ids).where('created_at > ?', 1.month.ago).popular.first(count)
end

.overall(count) ⇒ Object



25
26
27
# File 'app/services/popular_posts.rb', line 25

def self.overall(count)
  Post.visible.where(post_type_id: post_type_ids).popular.first(count)
end

.post_type_idsObject



5
6
7
# File 'app/services/popular_posts.rb', line 5

def self.post_type_ids
  PostType.where(slug: %w[news article]).pluck(:id)
end

.prepare(count = 5) ⇒ Object



9
10
11
12
13
14
15
# File 'app/services/popular_posts.rb', line 9

def self.prepare(count = 5)
  {
    week: week(count),
    month: month(count),
    overall: overall(count)
  }
end

.week(count) ⇒ Object



17
18
19
# File 'app/services/popular_posts.rb', line 17

def self.week(count)
  Post.visible.where(post_type_id: post_type_ids).where('created_at > ?', 7.days.ago).popular.first(count)
end