Class: CronSpec::CronSpecificationFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/cron-spec/cron_specification_factory.rb

Constant Summary collapse

WildcardPattern =
/\A\*\z/
SingleValuePattern =
/\A(\d+)\z/
RangePattern =
/\A(\d+)-(\d+)\z/
StepPattern =
/\A\*\/(\d+)\z/

Instance Method Summary collapse

Constructor Details

#initializeCronSpecificationFactory

Returns a new instance of CronSpecificationFactory.



10
11
12
13
14
# File 'lib/cron-spec/cron_specification_factory.rb', line 10

def initialize
  @single_value_pattern = SingleValuePattern
  @range_pattern = RangePattern
  @step_pattern = StepPattern
end

Instance Method Details

#parse(value_spec) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/cron-spec/cron_specification_factory.rb', line 16

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