Class: Cronos::Interval::RepeatInterval
- Inherits:
-
Object
- Object
- Cronos::Interval::RepeatInterval
- Defined in:
- lib/cronos.rb
Instance Method Summary collapse
- #calculate_intervals(base, initial = 0) ⇒ Object
- #hours ⇒ Object
-
#initialize(multiple, interval) ⇒ RepeatInterval
constructor
A new instance of RepeatInterval.
- #minutes ⇒ Object
- #months ⇒ Object
- #to_a ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(multiple, interval) ⇒ RepeatInterval
Returns a new instance of RepeatInterval.
259 260 261 |
# File 'lib/cronos.rb', line 259 def initialize(multiple, interval) @multiple, @interval = multiple, interval end |
Instance Method Details
#calculate_intervals(base, initial = 0) ⇒ Object
291 292 293 294 295 296 |
# File 'lib/cronos.rb', line 291 def calculate_intervals(base, initial = 0) repeats = (base / @multiple) - 1 set = [initial] 1.upto(repeats) {|factor| set << (factor * @multiple + initial) } @intervals = set end |
#hours ⇒ Object
271 272 273 274 275 276 277 278 |
# File 'lib/cronos.rb', line 271 def hours raise ArgumentError, 'Multiple of hours will not fit into a day' if (24 % @multiple) > 0 calculate_intervals(24) @interval.min = 0 @interval.hour = self @interval end |
#minutes ⇒ Object
263 264 265 266 267 268 269 |
# File 'lib/cronos.rb', line 263 def minutes raise ArgumentError, 'Multiple of minutes will not fit into an hour' if (60 % @multiple) > 0 calculate_intervals(60) @interval.min = self @interval end |
#months ⇒ Object
280 281 282 283 284 285 286 287 288 289 |
# File 'lib/cronos.rb', line 280 def months raise ArgumentError, 'Multiple of months will not fit into a year' if (12 % @multiple) > 0 calculate_intervals(12, 1) @interval.min ||= 0 @interval.hour ||= 0 @interval.day ||= 1 @interval.month = self @interval end |
#to_a ⇒ Object
302 303 304 |
# File 'lib/cronos.rb', line 302 def to_a @intervals end |
#to_s ⇒ Object
298 299 300 |
# File 'lib/cronos.rb', line 298 def to_s @intervals.join(',') end |