Async::Cron SourceAsyncCronPeriod

class Period

Definitions

def self.parse(string)

Parse a string into a period.

Signature

parameter string String | Nil

The string to parse.

Implementation

def self.parse(string)
	value, divisor = string&.split('/', 2)
	
	if divisor
		divisor = Integer(divisor)
	else
		divisor = 1
	end
	
	if value == '*'
		value = nil
	elsif value
		value = value.split(',').map do |part|
			if part =~ /\A(\d+)-(\d+)\z/
				Range.new(Integer($1), Integer($2))
			elsif part =~ /\A(-?\d+)\.\.(-?\d+)\z/
				Range.new(Integer($1), Integer($2))
			else
				Integer(part)
			end
		end
	end
	
	self.new(value, divisor)
end

def increment(time)

Increment the specific time unit to the next possible value.

Signature

parameter time Time

The time to increment, must be normalized.

Implementation

def increment(time)
	time.seconds = @successors[time.seconds]
end

def reset(time)

Reset the specific time unit to the first value.

Implementation

def reset(time)
	time.seconds = @values.first
end