Class: CronSpec::CronSpecificationFactory
- Inherits:
-
Object
- Object
- CronSpec::CronSpecificationFactory
- Defined in:
- lib/cron-spec/cron_specification_factory.rb
Overview
Base class for the definition of CronSpecificationFactory classes.
Direct Known Subclasses
DayFactory, DowFactory, HourFactory, MinuteFactory, MonthFactory
Constant Summary collapse
- WildcardPattern =
/\A\*\z/
- SingleValuePattern =
/\A(\d+)\z/
- RangePattern =
/\A(\d+)-(\d+)\z/
- StepPattern =
/\A\*\/(\d+)\z/
Instance Method Summary collapse
-
#initialize ⇒ CronSpecificationFactory
constructor
Constructs a new CronSpecificationFactory.
-
#parse(value_spec) ⇒ Object
Parses a unit of a cron specification.
Constructor Details
#initialize ⇒ CronSpecificationFactory
Constructs a new CronSpecificationFactory
16 17 18 19 20 |
# File 'lib/cron-spec/cron_specification_factory.rb', line 16 def initialize @single_value_pattern = SingleValuePattern @range_pattern = RangePattern @step_pattern = StepPattern end |
Instance Method Details
#parse(value_spec) ⇒ Object
Parses a unit of a cron specification. The supported patterns for parsing are one of:
-
Wildcard ‘*’
-
Single Scalar Value [0-9]+|(sun|mon|tue|wed|thu|fri|sat)|(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)
-
Range value (0-9, mon-fri, etc.)
-
Step value (*/[0-9]+)
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/cron-spec/cron_specification_factory.rb', line 31 def parse(value_spec) case value_spec when WildcardPattern WildcardCronValue.new(@lower_limit, @upper_limit) when @single_value_pattern SingleValueCronValue.new(@lower_limit, @upper_limit, convert_value($1)) when @range_pattern RangeCronValue.new(@lower_limit, @upper_limit, convert_value($1), convert_value($2)) when @step_pattern StepCronValue.new(@lower_limit, @upper_limit, $1.to_i) else raise "Unrecognized cron specification pattern." end end |