]> projects.mako.cc - selectricity/blob - app/models/quick_vote.rb
changed properties and the name of hyperchad to selectricity
[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     self.quickvote = 1
23   end
24
25   def candidatelist=(candlist)
26     @raw_candidates = candlist
27   end
28
29   def name
30     read_attribute( :name ).downcase()
31   end
32
33   def reviewed?
34     reviewed.to_i == 1
35   end
36
37   def create_candidates
38     @raw_candidates.each do |name|
39       candidate = Candidate.new({:name => name})
40       candidate.save
41       self.candidates << candidate
42     end
43   end
44 end

Benjamin Mako Hill || Want to submit a patch?