Election results in the London Borough of Sutton.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 

50 rindas
1006 B

  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. Candidate.get(loser).destroy
  32. puts "Merge completed. Here is the merged candidate:"
  33. puts
  34. show_candidate(winner)