Symphony::Metronome::
IntervalExpression class
Superclass | Object |
Extended With |
|
Parse natural English expressions of times and intervals.
in 30 minutes once an hour every 15 minutes for 2 days at 2014-05-01 at 2014-04-01 14:00:25 at 2pm starting at 2pm once a day start in 1 hour from now run every 5 seconds end at 11:15pm every other hour once a day ending in 1 week run once a minute for an hour starting in 6 days run each hour starting at 2010-01-05 09:00:00 10 times a minute for 2 days run 45 times every hour 30 times per day start at 2010-01-02 run 12 times and end on 2010-01-03 starting in an hour from now run 6 times a minute for 2 hours beginning a day from now, run 30 times per minute and finish in 2 weeks execute 12 times during the next 2 minutes
Constants
- COMMON_DECORATORS
Words/phrases in the expression that we’ll strip/ignore before parsing.
Attributes
- interval_expression_en_main RW
- interval_expression_error RW
- interval_expression_first_final RW
- interval_expression_start RW
- ending R
The valid end time for the schedule (for recurring events)
- interval R
The interval to wait before the event should be acted on.
- multiplier R
An optional interval multipler for expressing counts.
- recurring R
Does this event repeat?
- starting R
The valid start time for the schedule (for recurring events)
- valid R
Is the schedule expression parsable?
Public Class Methods
Parse a schedule expression exp
.
Parsing defaults to Time.now(), but if passed a time
object, all contexual times (2pm) are relative to it. If you know when an expression was generated, you can ‘reconstitute’ an interval object this way.
Public Instance Methods
Comparable interface, order by interval, ‘soonest’ first.
If this interval is on a stack somewhere and ready to fire, is it okay to do so based on the specified expression criteria?
Returns true
if it should fire, false
if it should not but could at a later attempt, and nil
if the interval has expired.
Inspection string.
Just return the original event expression.
Protected Instance Methods
Given a start
and ending
scanner position, return an ascii representation of the data slice.
Perform finishing logic and final sanity checks before returning a parsed object.
Given a time_arg
string and a type (:interval or :time), dispatch to the appropriate parser.
Parse a time_arg
interval string (“30 seconds”) into an Integer.
Parse a time_arg
string (anything parsable buy Time.parse()) into a Time object.
Parse and set the ending attribute, given a time_arg
string and the type
of string (interval or exact time)
Perform consistency and sanity checks before returning a Time object.
Parse and set the interval attribute, given a time_arg
string and the type
of string (interval or exact time)
Perform consistency and sanity checks before returning an integer representing the amount of time needed to sleep before firing the event.
Parse and set the starting attribute, given a time_arg
string and the type
of string (interval or exact time)