philiprehberger-cron_parser 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eeb369c781ff5bf8c316b443bf97ee4786ed74e11842f7f5de81a9071418bdb2
4
- data.tar.gz: ee7c9d64bae3aee0f9a7b617197e32c6af9816d09ad372c80031d748082f9ab2
3
+ metadata.gz: d11c034aa656522a0e2ca5e145ca68f974b1b0eb9aeafad15797ee5a53d859f1
4
+ data.tar.gz: 874e7abb865fa66511d7a407e7e0cc4ea0dfd8e8a637ff75225cffc9db5f0206
5
5
  SHA512:
6
- metadata.gz: c95125f661ce1799d954dc8766c494b784db4fcc7ccd1ad37ca638b4cd3a6a807560fa9640868d2a9eb91e89e8323604868a3f27fecf797324571f7d6d341b48
7
- data.tar.gz: c1464aa92d9df184418b6e211864f2ea30c7444822c955c5772482e2c7e24d10c5dc395de909c4baf7e17436cee4aba87c20a7ff72fd3241ab3c5049a3781ba2
6
+ metadata.gz: c8053224dd61f4defd352fbdf106351f995de7b16b6f10b610a40e99c47f577c0b27d241587aa74cd4299da2d7a4601c6879844eb63d68ce47dfcaa383ce5847
7
+ data.tar.gz: f830772d6a686fec8dcf8f857a68b4be1f162bf70f0ebde4146f7228b44f5aadc18dbe567ce8570fcd4d5c5fa3125ab2ef56313978cec0320caa5b7796d458b5
data/CHANGELOG.md CHANGED
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.3.0] - 2026-04-09
11
+
12
+ ### Added
13
+ - Named cron aliases (`@hourly`, `@daily`, `@midnight`, `@weekly`, `@monthly`, `@yearly`, `@annually`) with case-insensitive matching
14
+ - `valid?` and `validate` now accept alias expressions
15
+
10
16
  ## [0.2.0] - 2026-04-03
11
17
 
12
18
  ### Added
data/README.md CHANGED
@@ -69,6 +69,20 @@ Philiprehberger::CronParser.new('0 0 * * MON,WED,FRI') # specific days
69
69
  Philiprehberger::CronParser.new('0 0 * * 1,WED,5') # mixed numeric and named
70
70
  ```
71
71
 
72
+ ### Named Aliases
73
+
74
+ Standard crontab aliases are supported (case-insensitive):
75
+
76
+ ```ruby
77
+ Philiprehberger::CronParser.new('@hourly') # => 0 * * * *
78
+ Philiprehberger::CronParser.new('@daily') # => 0 0 * * *
79
+ Philiprehberger::CronParser.new('@midnight') # alias for @daily
80
+ Philiprehberger::CronParser.new('@weekly') # => 0 0 * * 0
81
+ Philiprehberger::CronParser.new('@monthly') # => 0 0 1 * *
82
+ Philiprehberger::CronParser.new('@yearly') # => 0 0 1 1 *
83
+ Philiprehberger::CronParser.new('@annually') # alias for @yearly
84
+ ```
85
+
72
86
  ### Validation
73
87
 
74
88
  ```ruby
@@ -30,13 +30,27 @@ module Philiprehberger
30
30
  weekday: 'day of week'
31
31
  }.freeze
32
32
 
33
- # @return [String] the original expression
33
+ ALIASES = {
34
+ '@yearly' => '0 0 1 1 *',
35
+ '@annually' => '0 0 1 1 *',
36
+ '@monthly' => '0 0 1 * *',
37
+ '@weekly' => '0 0 * * 0',
38
+ '@daily' => '0 0 * * *',
39
+ '@midnight' => '0 0 * * *',
40
+ '@hourly' => '0 * * * *'
41
+ }.freeze
42
+
43
+ # @return [String] the original (post-alias expansion) expression
34
44
  attr_reader :expression
35
45
 
36
- # @param expr [String] a 5-field cron expression
46
+ # @param expr [String] a 5-field cron expression or named alias (e.g. "@daily")
37
47
  # @raise [Error] if the expression is invalid
38
48
  def initialize(expr)
39
- @expression = expr.strip
49
+ stripped = expr.strip
50
+ stripped = ALIASES[stripped.downcase] if stripped.start_with?('@')
51
+ raise Error, "Unknown cron alias: #{expr.strip}" if stripped.nil?
52
+
53
+ @expression = stripped
40
54
  parts = @expression.split(/\s+/)
41
55
  raise Error, "Expected 5 fields, got #{parts.size}: #{@expression}" unless parts.size == 5
42
56
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Philiprehberger
4
4
  module CronParser
5
- VERSION = '0.2.0'
5
+ VERSION = '0.3.0'
6
6
  end
7
7
  end
@@ -37,6 +37,12 @@ module Philiprehberger
37
37
  def self.validate(expr)
38
38
  errors = []
39
39
  stripped = expr.strip
40
+ if stripped.start_with?('@')
41
+ alias_expanded = Expression::ALIASES[stripped.downcase]
42
+ return { valid: false, errors: ["Unknown cron alias: #{stripped}"] } if alias_expanded.nil?
43
+
44
+ stripped = alias_expanded
45
+ end
40
46
  parts = stripped.split(/\s+/)
41
47
 
42
48
  unless parts.size == 5
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: philiprehberger-cron_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philip Rehberger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-04-03 00:00:00.000000000 Z
11
+ date: 2026-04-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Parse standard 5-field cron expressions and calculate next/previous occurrences,
14
14
  match times against patterns, and generate human-readable descriptions.