Class: WeightedListRank::Strategy
- Inherits:
-
Object
- Object
- WeightedListRank::Strategy
- Defined in:
- lib/weighted_list_rank/strategy.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#calculate_score(list, item) ⇒ Numeric
Calculates the score for an item within a list.
-
#calculate_scores(list) ⇒ Array<Numeric>
Calculates the scores for every item in a list, returned in the same order as
list.items.
Instance Method Details
#calculate_score(list, item) ⇒ Numeric
Calculates the score for an item within a list. Must be implemented by subclass.
7 8 9 |
# File 'lib/weighted_list_rank/strategy.rb', line 7 def calculate_score(list, item) raise NotImplementedError end |
#calculate_scores(list) ⇒ Array<Numeric>
Calculates the scores for every item in a list, returned in the same order
as list.items.
This is the entry point RankingContext uses. The default implementation simply delegates to #calculate_score for each item, so strategies that implement only the single-item API continue to work unchanged.
Strategies whose scoring depends on values that are constant across the list (a total, a count, a normalizing factor) should override this and compute those values once, rather than recomputing them for every item.
24 25 26 |
# File 'lib/weighted_list_rank/strategy.rb', line 24 def calculate_scores(list) list.items.map { |item| calculate_score(list, item) } end |