]> projects.mako.cc - selectricity/blob - app/models/election.rb
fixed the string modification function and added support for a titlecase method
[selectricity] / app / models / election.rb
1 class Election < ActiveRecord::Base
2   has_many :candidates
3   has_many :voters
4   has_many :votes
5   belongs_to :user
6   validates_presence_of :name, :description
7
8   require 'date'
9
10   def startdate
11     read_attribute( :startdate ) || DateTime.now
12   end
13
14   def enddate
15     read_attribute( :enddate ) || DateTime.now + 14
16   end
17
18   def destroy
19     self.candidates.each do |candidate|
20       candidate.destroy
21     end
22     super
23   end
24
25   def start_blockers
26     reasons = []
27     
28     if self.candidates.length <= 1
29       reasons << "You must have at least two candidates."
30     end
31     
32     if self.voters.length <= 1
33       reasons << "You must have at least two voters."
34     end
35
36     reasons
37   end
38
39   def activate!
40     self.active = 1
41   end
42   
43   def quickvote?
44     quickvote.to_i == 1
45   end
46
47   def shortdesc
48     shortdesc = description.split(/\n/)[0]
49   end
50
51   def longdesc
52     longdesc = description.split(/\n/)[1..-1].join("")
53     longdesc.length > 0 ? longdesc : nil 
54   end
55 end

Benjamin Mako Hill || Want to submit a patch?