Module: Philiprehberger::CronKit::Parser
- Included in:
- Expression
- Defined in:
- lib/philiprehberger/cron_kit/parser.rb
Overview
Parsing logic for 5-field cron expressions. Extracted from Expression to keep class size manageable.
Constant Summary collapse
- FIELD_RANGES =
[ 0..59, # minute 0..23, # hour 1..31, # day of month 1..12, # month 0..6 # day of week ].freeze
- FIELD_NAMES =
%w[minute hour day-of-month month day-of-week].freeze
- MONTH_NAMES =
Three-letter month names (case-insensitive) mapped to their numeric value.
{ 'JAN' => 1, 'FEB' => 2, 'MAR' => 3, 'APR' => 4, 'MAY' => 5, 'JUN' => 6, 'JUL' => 7, 'AUG' => 8, 'SEP' => 9, 'OCT' => 10, 'NOV' => 11, 'DEC' => 12 }.freeze
- DAY_NAMES =
Three-letter weekday names (case-insensitive) mapped to their numeric value.
{ 'SUN' => 0, 'MON' => 1, 'TUE' => 2, 'WED' => 3, 'THU' => 4, 'FRI' => 5, 'SAT' => 6 }.freeze
- DOW_SUNDAY_ALIAS =
Sunday may be written as 7 in the day-of-week field (Vixie cron interop).
7
Instance Method Summary collapse
Instance Method Details
#parse_expression(expression) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/philiprehberger/cron_kit/parser.rb', line 32 def parse_expression(expression) parts = expression.split(/\s+/) raise ParseError, "expected 5 fields, got #{parts.length}: #{expression.inspect}" unless parts.length == 5 parts.each_with_index.map do |part, index| parse_field(part, FIELD_RANGES[index], FIELD_NAMES[index]) end end |