Class: IceT::Rule::Base
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
included, #to_hash
Constructor Details
#initialize(interval = 1) ⇒ Base
Returns a new instance of Base.
39
40
41
42
43
44
45
|
# File 'lib/ice_t/rule/base.rb', line 39
def initialize(interval = 1)
raise ArgumentError.new('Positive integer required') if interval.nil? ||
interval.to_i < 1 ||
interval % 1 != 0
@rule = self.class.name
@interval = interval
end
|
Instance Attribute Details
#interval ⇒ Object
Returns the value of attribute interval.
37
38
39
|
# File 'lib/ice_t/rule/base.rb', line 37
def interval
@interval
end
|
Class Method Details
.<=>(other) ⇒ Object
30
31
32
|
# File 'lib/ice_t/rule/base.rb', line 30
def <=>(other)
self.to_i <=> other.to_i
end
|
Instance Method Details
#<=>(other) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/ice_t/rule/base.rb', line 48
def <=>(other)
return unless other.class.respond_to?(:to_i)
if self.class == other.class
case
when self.interval == other.interval
0
when self.interval < other.interval
-1
when self.interval > other.interval
+1
end
else
case
when self.class.to_i < other.class.to_i
-1
when self.class.to_i > other.class.to_i
+1
end
end
end
|
#occurrences(start_time, end_time) ⇒ Object
69
70
71
72
73
74
|
# File 'lib/ice_t/rule/base.rb', line 69
def occurrences(start_time, end_time)
diff = IceT::TimeHelper.diff_by_unit(start_time, end_time, self.class.unit)
(0..diff).step(self.interval).map { |i|
start_time.advance(self.class.unit => i)
}
end
|