Class: MetricFu::Ranking
- Inherits:
-
Object
- Object
- MetricFu::Ranking
- Extended by:
- Forwardable
- Defined in:
- lib/base/ranking.rb
Instance Method Summary collapse
-
#initialize ⇒ Ranking
constructor
A new instance of Ranking.
- #percentile(item) ⇒ Object
- #top(num = nil) ⇒ Object
Constructor Details
#initialize ⇒ Ranking
Returns a new instance of Ranking.
6 7 8 |
# File 'lib/base/ranking.rb', line 6 def initialize @items_to_score = {} end |
Instance Method Details
#percentile(item) ⇒ Object
18 19 20 21 22 |
# File 'lib/base/ranking.rb', line 18 def percentile(item) index = sorted_items.index(item) worse_item_count = (length - (index+1)) worse_item_count.to_f/length end |
#top(num = nil) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/base/ranking.rb', line 10 def top(num=nil) if(num.is_a?(Numeric)) sorted_items[0,num] else sorted_items end end |