Class: TopicParticipantsSummary
- Inherits:
-
Object
- Object
- TopicParticipantsSummary
- Defined in:
- app/models/topic_participants_summary.rb
Overview
This is used on a topic page
Constant Summary collapse
- PARTICIPANT_COUNT =
should match maxUserCount in topic list
5
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#topic ⇒ Object
readonly
Returns the value of attribute topic.
Instance Method Summary collapse
-
#initialize(topic, options = {}) ⇒ TopicParticipantsSummary
constructor
A new instance of TopicParticipantsSummary.
- #is_latest_poster?(user) ⇒ Boolean
- #new_topic_poster_for(user) ⇒ Object
- #summary ⇒ Object
- #top_participants ⇒ Object
- #user_ids ⇒ Object
- #user_lookup ⇒ Object
Constructor Details
#initialize(topic, options = {}) ⇒ TopicParticipantsSummary
Returns a new instance of TopicParticipantsSummary.
8 9 10 11 12 |
# File 'app/models/topic_participants_summary.rb', line 8 def initialize(topic, = {}) @topic = topic @options = @user = [:user] end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'app/models/topic_participants_summary.rb', line 5 def @options end |
#topic ⇒ Object (readonly)
Returns the value of attribute topic.
5 6 7 |
# File 'app/models/topic_participants_summary.rb', line 5 def topic @topic end |
Instance Method Details
#is_latest_poster?(user) ⇒ Boolean
25 26 27 |
# File 'app/models/topic_participants_summary.rb', line 25 def is_latest_poster?(user) topic.last_post_user_id == user.id end |
#new_topic_poster_for(user) ⇒ Object
18 19 20 21 22 23 |
# File 'app/models/topic_participants_summary.rb', line 18 def new_topic_poster_for(user) TopicPoster.new.tap do |topic_poster| topic_poster.user = user topic_poster.extras = "latest" if is_latest_poster?(user) end end |
#summary ⇒ Object
14 15 16 |
# File 'app/models/topic_participants_summary.rb', line 14 def summary top_participants.compact.map(&method(:new_topic_poster_for)) end |
#top_participants ⇒ Object
29 30 31 |
# File 'app/models/topic_participants_summary.rb', line 29 def top_participants user_ids.map { |id| user_lookup[id] }.compact.uniq.take(PARTICIPANT_COUNT) end |
#user_ids ⇒ Object
33 34 35 36 |
# File 'app/models/topic_participants_summary.rb', line 33 def user_ids return [] unless @user [topic.user_id] + topic.allowed_user_ids - [@user.id] end |
#user_lookup ⇒ Object
38 39 40 |
# File 'app/models/topic_participants_summary.rb', line 38 def user_lookup @user_lookup ||= [:user_lookup] || UserLookup.new(user_ids) end |