Election results in the London Borough of Sutton.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

51 lines
1.1 KiB

  1. require_relative "../models"
  2. def show_candidate(id)
  3. c = Candidate.get(id)
  4. template = "%6s\t%50s\t%20s\t%3s"
  5. puts template % [ c.id, c.forenames, c.surname ]
  6. ccy_template = "%20s\t%15s\t%20s\t%20s"
  7. c.candidacies.each do |ccy|
  8. puts template % [ ccy.election.body.name, ccy.election.d, ccy.district.name, ccy.party.name]
  9. end
  10. end
  11. winner = ARGV.shift
  12. loser = ARGV.shift
  13. puts "WINNER"
  14. show_candidate(winner)
  15. puts
  16. puts "LOSER"
  17. show_candidate(loser)
  18. puts "Are you sure you want to merge these two candidates? The loser will be deleted. (Y or N)"
  19. answer = gets.chomp.downcase
  20. unless answer == 'y'
  21. puts "Aborting. No changes made to the database."
  22. exit
  23. end
  24. # Transfer all the loser's candidacies to the winner
  25. repository(:default).adapter.select("
  26. UPDATE candidacies
  27. SET candidate_id = #{winner}
  28. WHERE candidate_id = #{loser}
  29. ")
  30. # Delete the loser candidate
  31. DeletedCandidate.create(:old_candidate_id => loser, :candidate_id => winner)
  32. Candidate.get(loser).destroy
  33. puts "Merge completed. Here is the merged candidate:"
  34. puts
  35. show_candidate(winner)