Class: BBLib::Cron
- Inherits:
-
Object
- Object
- BBLib::Cron
- Defined in:
- lib/time/cron.rb
Instance Attribute Summary collapse
-
#exp ⇒ Object
Returns the value of attribute exp.
-
#parts ⇒ Object
readonly
Returns the value of attribute parts.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Class Method Summary collapse
- .next(exp, count: 1, time: Time.now) ⇒ Object
- .prev(exp, count: 1, time: Time.now) ⇒ Object
- .valid?(exp) ⇒ Boolean
Instance Method Summary collapse
- #closest(exp = @exp, direction: 1, count: 1, time: Time.now) ⇒ Object
-
#initialize(exp) ⇒ Cron
constructor
A new instance of Cron.
- #next(exp = @exp, count: 1, time: Time.now) ⇒ Object
- #prev(exp = @exp, count: 1, time: Time.now) ⇒ Object
- #valid?(exp) ⇒ Boolean
Constructor Details
Instance Attribute Details
#exp ⇒ Object
Returns the value of attribute exp.
4 5 6 |
# File 'lib/time/cron.rb', line 4 def exp @exp end |
#parts ⇒ Object (readonly)
Returns the value of attribute parts.
4 5 6 |
# File 'lib/time/cron.rb', line 4 def parts @parts end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
4 5 6 |
# File 'lib/time/cron.rb', line 4 def time @time end |
Class Method Details
.next(exp, count: 1, time: Time.now) ⇒ Object
33 34 35 |
# File 'lib/time/cron.rb', line 33 def self.next exp, count: 1, time: Time.now t = BBLib::Cron.new(exp).next(count:count, time:time) end |
.prev(exp, count: 1, time: Time.now) ⇒ Object
37 38 39 |
# File 'lib/time/cron.rb', line 37 def self.prev exp, count: 1, time: Time.now BBLib::Cron.new(exp).prev(count:count, time:time) end |
.valid?(exp) ⇒ Boolean
41 42 43 |
# File 'lib/time/cron.rb', line 41 def self.valid? exp !(numeralize(exp) =~ /\A(.*?\s){4,5}.*?\S\z/).nil? end |
Instance Method Details
#closest(exp = @exp, direction: 1, count: 1, time: Time.now) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/time/cron.rb', line 11 def closest exp = @exp, direction:1, count: 1, time: Time.now if exp then self.exp = exp end results = [] return results unless @exp (1..count).each{ |i| results.push next_time(i == 1 ? time : results.last, direction) } count <= 1 ? results.first : results.reject{ |r| r.nil? } end |
#next(exp = @exp, count: 1, time: Time.now) ⇒ Object
19 20 21 |
# File 'lib/time/cron.rb', line 19 def next exp = @exp, count: 1, time: Time.now closest exp, count:count, time:time, direction:1 end |
#prev(exp = @exp, count: 1, time: Time.now) ⇒ Object
23 24 25 |
# File 'lib/time/cron.rb', line 23 def prev exp = @exp, count: 1, time: Time.now closest exp, count:count, time:time, direction:-1 end |