Module: Crony
- Defined in:
- lib/crony.rb,
lib/crony/parser.rb,
lib/crony/version.rb,
lib/crony/formatters/cron_struct.rb,
lib/crony/presenters/day_presenter.rb,
lib/crony/formatters/hour_formatter.rb,
lib/crony/formatters/year_formatter.rb,
lib/crony/presenters/time_presenter.rb,
lib/crony/presenters/year_presenter.rb,
lib/crony/formatters/month_formatter.rb,
lib/crony/formatters/minute_formatter.rb,
lib/crony/formatters/day_of_week_formatter.rb,
lib/crony/formatters/day_of_month_formatter.rb
Defined Under Namespace
Modules: Formatters, TimePresenter
Classes: CronStruct, DayPresenter, Parser, YearPresenter
Constant Summary
collapse
- VERSION =
"0.1.1"
Class Method Summary
collapse
Class Method Details
.parse(expression) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/crony.rb', line 6
def self.parse(expression)
return 'Invalid Format' if expression.split(/\s+/).size < 5
@minute, @hour, @day, @month, @weekday, @year = expression.split(/\s+/)
return 'Invalid Format' unless valid?
time = TimePresenter.parse(@minute, @hour)
day = DayPresenter.parse(@day, @month, @weekday)
year = !!@year ? YearPresenter.parse(@year) : ''
result = "#{time} #{day} #{year}".strip.squeeze(' ').gsub(/ ,/, ',')
result.sub(/^(.)/) { $1 == 'x' ? $1 : $1.upcase}
end
|
.valid? ⇒ Boolean
19
20
21
22
23
24
25
26
|
# File 'lib/crony.rb', line 19
def self.valid?
@minute =~ /^[\*\/,\-\d]+$/ &&
@hour =~ /^[\*\/,\-\d]+$/ &&
@day =~ /^[\*\/,\-\?LW\d]+$/ &&
@month =~ /^[\*\/,\-\djanfebmrpyjulgsoctv]+$/i &&
@weekday =~ /^[\*\/,\-\?\dsunmotewdhfriaL#]+$/i &&
(@year.nil? || @year =~ /^[\*\/,\-\d]*$/)
end
|