Class: TopicPostersSummary

Inherits:
Object
  • Object
show all
Defined in:
app/models/topic_posters_summary.rb

Overview

This is used in topic lists

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(topic, options = {}) ⇒ TopicPostersSummary

Returns a new instance of TopicPostersSummary.



18
19
20
21
22
# File 'app/models/topic_posters_summary.rb', line 18

def initialize(topic, options = {})
  @topic = topic
  @options = options
  @translations = options[:translations] || TopicPostersSummary.translations
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



16
17
18
# File 'app/models/topic_posters_summary.rb', line 16

def options
  @options
end

#topicObject (readonly)

Returns the value of attribute topic.



16
17
18
# File 'app/models/topic_posters_summary.rb', line 16

def topic
  @topic
end

Class Method Details

.translationsObject

localization is fast, but this allows us to avoid calling it in a loop which adds up



7
8
9
10
11
12
13
14
# File 'app/models/topic_posters_summary.rb', line 7

def self.translations
  {
    original_poster: I18n.t(:original_poster),
    most_recent_poster: I18n.t(:most_recent_poster),
    frequent_poster: I18n.t(:frequent_poster),
    joiner: I18n.t(:poster_description_joiner),
  }
end

Instance Method Details

#summaryObject



24
25
26
# File 'app/models/topic_posters_summary.rb', line 24

def summary
  sorted_top_posters.compact.map(&method(:new_topic_poster_for))
end