weighted_list_rank 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/weighted_list_rank/strategies/exponential.rb +4 -0
- data/lib/weighted_list_rank/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4056bebc06742afb336a7dd554e0147b782981a4cddb6b56a80239cccd9f6ae3
|
|
4
|
+
data.tar.gz: 3e1932ffba58a189db05a444cd9eb44581776119ac1566b3ea2f853c7657cb5f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 59e687f40b55f56ad37b478505f357065c1c0237453fd2a97de8b03f525a28365b4daee4ee3b36de7927f4fcfb448b590071c1b9f7776a6751fcaf975399e2ec
|
|
7
|
+
data.tar.gz: 75b5e64e86f4de6168804682705b105bec73cb59ca6304afc1cf39deb5ca7ea988b257a9dca6f4bbc3e00ba56b8614986b5d128829eb762ddc90a9ff3ba388f2
|
data/CHANGELOG.md
CHANGED
|
@@ -29,6 +29,10 @@ module WeightedListRank
|
|
|
29
29
|
# @return [Float] the calculated score for the item, adjusted by the list's weight and the specified exponent.
|
|
30
30
|
def calculate_score(list, item)
|
|
31
31
|
rank_position = item.position
|
|
32
|
+
|
|
33
|
+
# if there are no positions, then just return the list weight
|
|
34
|
+
return list.weight if rank_position.nil?
|
|
35
|
+
|
|
32
36
|
num_items = list.items.count
|
|
33
37
|
|
|
34
38
|
contribution = ((num_items + 1 - rank_position)**exponent) / num_items.to_f
|