Class: FilterBestPosts

Inherits:
Object
  • Object
show all
Defined in:
lib/filter_best_posts.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(topic, filtered_posts, limit, options = {}) ⇒ FilterBestPosts

Returns a new instance of FilterBestPosts.



6
7
8
9
10
11
12
# File 'lib/filter_best_posts.rb', line 6

def initialize(topic, filtered_posts, limit, options = {})
  @filtered_posts = filtered_posts
  @topic = topic
  @limit = limit
  options.each { |key, value| self.instance_variable_set("@#{key}".to_sym, value) }
  filter
end

Instance Attribute Details

#filtered_postsObject

Returns the value of attribute filtered_posts.



4
5
6
# File 'lib/filter_best_posts.rb', line 4

def filtered_posts
  @filtered_posts
end

#postsObject

Returns the value of attribute posts.



4
5
6
# File 'lib/filter_best_posts.rb', line 4

def posts
  @posts
end

Instance Method Details

#filterObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/filter_best_posts.rb', line 14

def filter
  @posts =
    if @min_replies && @topic.posts_count < @min_replies + 1
      Post.none
    else
      filter_posts_liked_by_moderators
      setup_posts
      filter_posts_based_on_trust_level
      filter_posts_based_on_score
      sort_posts
    end
end