lib/picky/query/combinations.rb in picky-0.3.0 vs lib/picky/query/combinations.rb in picky-0.9.0
- old
+ new
@@ -17,17 +17,20 @@
def hash
@combinations.hash
end
+ # Uses user specific weights to calculate a score for the combinations.
#
- #
- # TODO Rewrite.
- #
def calculate_score weights
- @score = @combinations.sum &:weight
- @score += weights.score @combinations
- @score
+ @score ||= sum_score
+ @score + add_score(weights) # TODO Ok to just cache the weights?
+ end
+ def sum_score
+ @combinations.sum &:weight
+ end
+ def add_score weights
+ weights.score @combinations
end
# Gets all ids for the allocations.
#
# Sorts the ids by size and & through them in the following order (sizes):
\ No newline at end of file