Class: CronUnit
- Inherits:
-
Object
- Object
- CronUnit
- Defined in:
- lib/khronotab/cron_unit.rb
Instance Attribute Summary collapse
-
#cron_form ⇒ Object
Returns the value of attribute cron_form.
-
#maximum ⇒ Object
Returns the value of attribute maximum.
-
#minimum ⇒ Object
Returns the value of attribute minimum.
Instance Method Summary collapse
- #contains?(value) ⇒ Boolean
- #expand_interval(segment) ⇒ Object
- #expand_range(segment) ⇒ Object
- #expanded_form ⇒ Object
-
#initialize(cron, min, max) ⇒ CronUnit
constructor
A new instance of CronUnit.
- #to_s ⇒ Object
Constructor Details
#initialize(cron, min, max) ⇒ CronUnit
Returns a new instance of CronUnit.
4 5 6 7 8 |
# File 'lib/khronotab/cron_unit.rb', line 4 def initialize(cron, min, max) @cron_form = cron @minimum = min @maximum = max end |
Instance Attribute Details
#cron_form ⇒ Object
Returns the value of attribute cron_form.
2 3 4 |
# File 'lib/khronotab/cron_unit.rb', line 2 def cron_form @cron_form end |
#maximum ⇒ Object
Returns the value of attribute maximum.
2 3 4 |
# File 'lib/khronotab/cron_unit.rb', line 2 def maximum @maximum end |
#minimum ⇒ Object
Returns the value of attribute minimum.
2 3 4 |
# File 'lib/khronotab/cron_unit.rb', line 2 def minimum @minimum end |
Instance Method Details
#contains?(value) ⇒ Boolean
10 11 12 |
# File 'lib/khronotab/cron_unit.rb', line 10 def contains?(value) .include?(value) end |
#expand_interval(segment) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/khronotab/cron_unit.rb', line 19 def (segment) counter = 0 times = [] interval = segment.split('/').map! { |x| if x == '*' x = @maximum else x.to_i end } while counter < interval[0] times.push(counter) counter += interval[1] end times end |
#expand_range(segment) ⇒ Object
14 15 16 17 |
# File 'lib/khronotab/cron_unit.rb', line 14 def (segment) range = segment.split('-').map! { |x| x.to_i } (range[0] .. range[1]).to_a end |
#expanded_form ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/khronotab/cron_unit.rb', line 36 def values = [] @cron_form.split(',').each do |segment| case segment when /-/ #range values.concat((segment)) when /\// #interval values.concat((segment)) when /[*]/ values.concat((@minimum .. @maximum).to_a) else values << segment.to_i end end values.sort.uniq end |
#to_s ⇒ Object
53 54 55 |
# File 'lib/khronotab/cron_unit.rb', line 53 def to_s @cron_form end |