Class: Ai4r::Classifiers::Votes

Inherits:
Object
  • Object
show all
Defined in:
lib/ai4r/classifiers/votes.rb

Instance Method Summary collapse

Constructor Details

#initializeVotes

Returns a new instance of Votes.


14
15
16
# File 'lib/ai4r/classifiers/votes.rb', line 14

def initialize
  self.tally_sheet = Hash.new(0)
end

Instance Method Details

#get_winnerObject


26
27
28
29
30
# File 'lib/ai4r/classifiers/votes.rb', line 26

def get_winner
  n = 0 # used to create a stable sort of the tallys
  sorted_sheet = tally_sheet.sort_by { |_, score| n += 1; [score, n] }
  sorted_sheet.last.first
end

#increment_category(category) ⇒ Object


18
19
20
# File 'lib/ai4r/classifiers/votes.rb', line 18

def increment_category(category)
  tally_sheet[category] += 1
end

#tally_for(category) ⇒ Object


22
23
24
# File 'lib/ai4r/classifiers/votes.rb', line 22

def tally_for(category)
  tally_sheet[category]
end