rescue event register and implement transition state override
[god.git] / lib / god / conditions / tries.rb
blobcd35e45683e021564b8361f25bc9db850704ae74
1 module God
2   module Conditions
3     
4     class Tries < PollCondition
5       attr_accessor :times
6       
7       def prepare
8         if self.times.kind_of?(Integer)
9           self.times = [self.times, self.times]
10         end
11         
12         @timeline = Timeline.new(self.times[1])
13       end
14     
15       def valid?
16         valid = true
17         valid &= complain("You must specify the 'times' attribute for :tries") if self.times.nil?
18         valid
19       end
20     
21       def test
22         @timeline.push(true)
23         if @timeline.select { |x| x }.size >= self.times.first
24           @timeline.clear
25           return true
26         else
27           return false
28         end
29       end
30     end
31     
32   end
33 end