]> projects.mako.cc - selectricity/blob - app/models/quick_vote.rb
8d4e6e82141f8b8c67dab67d0103c170a97f0324
[selectricity] / app / models / quick_vote.rb
1 class QuickVote < Election
2   after_validation :create_candidates
3   validates_uniqueness_of :name
4   attr_accessor :raw_candidates
5   attr_accessor :reviewed
6
7   def validate
8     if @raw_candidates.length < 2
9       errors.add("You must list at least two candidates.")
10     end
11
12     if name =~ /[^A-Za-z0-9]/
13       errors.add("The name must only include numbers and letters.")
14     end
15   end
16   
17   def initialize(params={})
18     super
19     self.enddate =  Time.now + 30.days
20     self.active = 1
21     self.anonymous = 1
22   end
23
24   def candidatelist=(candlist)
25     @raw_candidates = candlist
26   end
27
28   def name
29     read_attribute( :name ).downcase()
30   end
31
32   def reviewed?
33     reviewed.to_i == 1
34   end
35
36   def create_candidates
37     @raw_candidates.each do |name|
38       candidate = Candidate.new({:name => name})
39       self.candidates << candidate
40     end
41   end
42 end

Benjamin Mako Hill || Want to submit a patch?