class MetricFu::Ranking

Public Class Methods

new() click to toggle source
# File lib/base/ranking.rb, line 6
def initialize
  @items_to_score = {}
end

Public Instance Methods

percentile(item) click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

sorted_items() click to toggle source
# File lib/base/ranking.rb, line 29
def sorted_items
  @sorted_items ||= @items_to_score.sort_by {|item, score| -score}.map {|item, score| item}
end