Class: Schulze::Election
- Inherits:
-
Object
- Object
- Schulze::Election
- Defined in:
- lib/schulze/election.rb
Class Method Summary collapse
Instance Method Summary collapse
- #<<(ballot) ⇒ Object
-
#initialize ⇒ Election
constructor
A new instance of Election.
- #results ⇒ Object
Constructor Details
#initialize ⇒ Election
Returns a new instance of Election.
15 16 17 18 |
# File 'lib/schulze/election.rb', line 15 def initialize @ballots = [] @candidates = Set.new end |
Class Method Details
.perform_for_dir_glob(dir_glob) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/schulze/election.rb', line 7 def self.perform_for_dir_glob dir_glob election = new dir_glob.each do |filename| election << Ballot.new_from_filename(filename) end election.results end |
Instance Method Details
#<<(ballot) ⇒ Object
20 21 22 23 |
# File 'lib/schulze/election.rb', line 20 def << ballot @ballots << ballot @candidates.merge ballot.candidates end |
#results ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/schulze/election.rb', line 25 def results candidate_array = @candidates.to_a.sort pairwise = generate_pairwise_preferences candidate_array path_strengths = generate_path_strengths pairwise if !(defined?(SILENCE) && SILENCE) path_strengths.each_with_index do |row, idx| puts("%20s %s" % [candidate_array[idx], row.inspect]) end end generate_orderings candidate_array, path_strengths end |