Class: AWSCronParser::FugitAdapter
- Inherits:
-
Object
- Object
- AWSCronParser::FugitAdapter
- Defined in:
- lib/aws_cron_parser/fugit_adapter.rb
Overview
Adapter to use Fugit gem as replacement for parse-cron Provides a unified interface for next/last time calculations
Instance Method Summary collapse
-
#initialize(source, time_source = Time) ⇒ FugitAdapter
constructor
A new instance of FugitAdapter.
-
#last(now) ⇒ Object
Get previous occurrence of the cron expression.
-
#next(now) ⇒ Object
Get next occurrence of the cron expression.
-
#original ⇒ Object
Get the original source expression.
Constructor Details
#initialize(source, time_source = Time) ⇒ FugitAdapter
Returns a new instance of FugitAdapter.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/aws_cron_parser/fugit_adapter.rb', line 9 def initialize(source, time_source = Time) @source = source @time_source = time_source @normalized_source = normalize_source(source) # Parse with fugit @fugit_cron = Fugit::Cron.parse(@normalized_source) raise ArgumentError, "Invalid CRON expression: #{source}" if @fugit_cron.nil? end |
Instance Method Details
#last(now) ⇒ Object
Get previous occurrence of the cron expression
27 28 29 30 |
# File 'lib/aws_cron_parser/fugit_adapter.rb', line 27 def last(now) result = @fugit_cron.previous_time(now) normalize_to_time_zone(result) end |
#next(now) ⇒ Object
Get next occurrence of the cron expression
21 22 23 24 |
# File 'lib/aws_cron_parser/fugit_adapter.rb', line 21 def next(now) result = @fugit_cron.next_time(now) normalize_to_time_zone(result) end |
#original ⇒ Object
Get the original source expression
33 34 35 |
# File 'lib/aws_cron_parser/fugit_adapter.rb', line 33 def original @source end |