Class: SearchAndRank::ClassMethods::RankedResults

Inherits:
Object
  • Object
show all
Defined in:
lib/rankings/searchandrank.rb

Instance Method Summary collapse

Constructor Details

#initializeRankedResults

Returns a new instance of RankedResults.



29
30
31
# File 'lib/rankings/searchandrank.rb', line 29

def initialize
  @results = {}
end

Instance Method Details

#add_result(objects) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/rankings/searchandrank.rb', line 33

def add_result(objects)
  objects.each do |o|
    if @results[o]
      @results[o] += 1
    else
      @results[o] = 1
    end
  end
end

#objectsObject



48
49
50
# File 'lib/rankings/searchandrank.rb', line 48

def objects
  @results.map{|r| r.first}
end

#sortObject



43
44
45
46
# File 'lib/rankings/searchandrank.rb', line 43

def sort
  @results = @results.sort{|a,b| b[1]<=>a[1]}
  self
end