Class: SearchAndRank::ClassMethods::RankedResults
- Inherits:
-
Object
- Object
- SearchAndRank::ClassMethods::RankedResults
- Defined in:
- lib/rankings/searchandrank.rb
Instance Method Summary collapse
- #add_result(objects) ⇒ Object
-
#initialize ⇒ RankedResults
constructor
A new instance of RankedResults.
- #objects ⇒ Object
- #sort ⇒ Object
Constructor Details
#initialize ⇒ RankedResults
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 |
#objects ⇒ Object
48 49 50 |
# File 'lib/rankings/searchandrank.rb', line 48 def objects @results.map{|r| r.first} end |
#sort ⇒ Object
43 44 45 46 |
# File 'lib/rankings/searchandrank.rb', line 43 def sort @results = @results.sort{|a,b| b[1]<=>a[1]} self end |