Class: Cronin::AbstractTiming

Inherits:
Object
  • Object
show all
Defined in:
lib/cronin/abstract_timing.rb

Overview

Class contain all logic for getting timing for minute, hour, week day, month day and month

Direct Known Subclasses

Hours, Minutes, MonthDays, Months, WeekDays

Instance Method Summary collapse

Constructor Details

#initialize(cron_value) ⇒ AbstractTiming

Returns a new instance of AbstractTiming.



5
6
7
# File 'lib/cronin/abstract_timing.rb', line 5

def initialize(cron_value)
  @cron_value = cron_value
end

Instance Method Details

#max_valueObject



31
32
33
# File 'lib/cronin/abstract_timing.rb', line 31

def max_value
  self.class.max_value
end

#min_valueObject



27
28
29
# File 'lib/cronin/abstract_timing.rb', line 27

def min_value
  self.class.min_value
end

#timingObject

Returns array of fixnum, when it should be execute



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/cronin/abstract_timing.rb', line 10

def timing
  case @cron_value
  when '*'
    return (min_value..max_value).to_a
  when /^\d{1,2}/
    number = @cron_value.to_i
    if number >= min_value && number <= max_value
      return [number]
    else
      raise ArgumentError, 'wrong value for this entry'
    end
  when /\*\/(\d+)/
    number = $1.to_i
    return (min_value..max_value).to_a.delete_if {|elem| elem % number != 0}
  end
end