Class: ScoreCalculator
- Inherits:
-
Object
- Object
- ScoreCalculator
- Defined in:
- lib/score_calculator.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#calculate(opts = nil) ⇒ Object
Calculate the score for all posts based on the weightings.
-
#initialize(weightings = nil) ⇒ ScoreCalculator
constructor
A new instance of ScoreCalculator.
Constructor Details
#initialize(weightings = nil) ⇒ ScoreCalculator
Returns a new instance of ScoreCalculator.
8 9 10 |
# File 'lib/score_calculator.rb', line 8 def initialize(weightings = nil) @weightings = weightings || ScoreCalculator.default_score_weights end |
Class Method Details
.default_score_weights ⇒ Object
4 5 6 |
# File 'lib/score_calculator.rb', line 4 def self.default_score_weights { reply_count: 5, like_score: 15, incoming_link_count: 5, bookmark_count: 2, reads: 0.2 } end |
Instance Method Details
#calculate(opts = nil) ⇒ Object
Calculate the score for all posts based on the weightings
13 14 15 16 17 |
# File 'lib/score_calculator.rb', line 13 def calculate(opts = nil) update_posts_score(opts) update_posts_rank(opts) update_topics_rank(opts) end |