fugit 1.2.3 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of fugit might be problematic. Click here for more details.

Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/README.md +15 -0
  4. data/lib/fugit.rb +1 -1
  5. data/lib/fugit/nat.rb +52 -14
  6. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4814a18c1285406d94b93d1ae579c0e26f541653
4
- data.tar.gz: 74fa964320d7596ee309edf6f418f714893ae813
3
+ metadata.gz: 57336fd846b610ad0c361564a8025f3ccb752025
4
+ data.tar.gz: 4effff19a32313a7eefad03b6ba1eebe1d056e62
5
5
  SHA512:
6
- metadata.gz: 1e6039af8e976c6839e34e84f7c2d17eddbde91acd12b91f1f113c2946aac5826a384a55d8fc6d5cdf0042f864ca8ba35882e5a96fc5d04467c0825084641c8a
7
- data.tar.gz: c02ee46cf23803f967b086bfa14a19137339733bc73a732358c721e6ce88384d7b432fedb7a2dea22f25913c32316a1a1210ca6d63bbf0f600d79ae192b0ec46
6
+ metadata.gz: 429bc3055890b87c7a1cb78da8d713844f73de3bc162295ce7e0688179800caec9c5bb96b792276b1bf71ee40de1cee50070553ccbeb98e6150abe7b168b3f9c
7
+ data.tar.gz: 95fa1fc74e5ebdef176edd772d7978f8c845ecd9d9e465450ae3d61d6d7cebca89bca8cb43cc1e1e4986ff22a392fb08c58525d4ed5c5a9cd31ee8539efd4738
@@ -2,6 +2,12 @@
2
2
  # CHANGELOG.md
3
3
 
4
4
 
5
+ ## fugit 1.3.0 released 2019-07-21
6
+
7
+ * Introduce Fugit.parse_nat('every day at 18:00 and 19:15', multi: true)
8
+ * Rework AM/PM parsing
9
+
10
+
5
11
  ## fugit 1.2.3 released 2019-07-16
6
12
 
7
13
  * Allow for "from Monday to Friday at 19:22", gh-25
data/README.md CHANGED
@@ -250,6 +250,21 @@ Directly with `Fugit.parse(s)` is OK too:
250
250
  Fugit.parse('every day at five') # ==> Fugit::Cron instance '0 5 * * *'
251
251
  ```
252
252
 
253
+ ### Ambiguous nats
254
+
255
+ Not all strings result in a clean, single, cron expression.
256
+
257
+ ```ruby
258
+ Fugit::Nat.parse('every day at 16:00 and 18:00', multi: true)
259
+ # ==> [ '0 16,18 * * *' ]
260
+ Fugit::Nat.parse('every day at 16:15 and 18:30')
261
+ # ==> [ '15 16 * * *' ]
262
+ Fugit::Nat.parse('every day at 16:15 and 18:30', multi: true)
263
+ # ==> [ '15 16 * * *', '30 18 * * *' ]
264
+ Fugit::Nat.parse('every day at 16:15 and 18:30', multi: :fail)
265
+ # ==> ArgumentError: multiple crons in "every day at 16:15 and 18:30" (15 16 * * * | 30 18 * * *)
266
+ ```
267
+
253
268
 
254
269
  ## LICENSE
255
270
 
@@ -1,7 +1,7 @@
1
1
 
2
2
  module Fugit
3
3
 
4
- VERSION = '1.2.3'
4
+ VERSION = '1.3.0'
5
5
  end
6
6
 
7
7
  require 'time'
@@ -19,9 +19,9 @@ module Fugit
19
19
 
20
20
  return nil unless a
21
21
 
22
- return parse_cron(a, opts) \
22
+ return parse_crons(s, a, opts) \
23
23
  if a.include?([ :flag, 'every' ])
24
- return parse_cron(a, opts) \
24
+ return parse_crons(s, a, opts) \
25
25
  if a.include?([ :flag, 'from' ]) && a.find { |e| e[0] == :day_range }
26
26
 
27
27
  nil
@@ -33,7 +33,35 @@ module Fugit
33
33
  fail(ArgumentError.new("could not parse a nat #{s.inspect}"))
34
34
  end
35
35
 
36
- def parse_cron(a, opts={})
36
+ protected
37
+
38
+ def parse_crons(s, a, opts)
39
+
40
+ dhs, aa =
41
+ a.partition { |e| e[0] == :digital_hour }
42
+ dms =
43
+ dhs.collect { |dh| dh[1][1] }.uniq
44
+
45
+ crons =
46
+ if dhs.empty? || dms.size == 1
47
+ [ parse_cron(a, opts) ]
48
+ else
49
+ dhs.collect { |dh| parse_cron([ dh ] + aa, opts) }
50
+ end
51
+
52
+ fail ArgumentError.new(
53
+ "multiple crons in #{s.inspect} " +
54
+ "(#{crons.collect(&:original).join(' | ')})"
55
+ ) if opts[:multi] == :fail && crons.size > 1
56
+
57
+ if opts[:multi]
58
+ crons
59
+ else
60
+ crons.first
61
+ end
62
+ end
63
+
64
+ def parse_cron(a, opts)
37
65
 
38
66
  h = { min: nil, hou: [], dom: nil, mon: nil, dow: nil }
39
67
  hkeys = h.keys
@@ -50,8 +78,6 @@ module Fugit
50
78
  (h[:dow] ||= []) << val
51
79
  elsif key == :day_range
52
80
  (h[:dow] ||= []) << val.collect { |v| v.to_s[0, 3] }.join('-')
53
- elsif key == :flag && val == 'pm' && h[:hou]
54
- h[:hou][-1] = h[:hou][-1] + 12
55
81
  elsif key == :tz
56
82
  h[:tz] = val
57
83
  elsif key == :duration
@@ -75,8 +101,6 @@ module Fugit
75
101
  Fugit::Cron.parse(s)
76
102
  end
77
103
 
78
- protected
79
-
80
104
  def process_duration(h, interval, value)
81
105
 
82
106
  send("process_duration_#{interval}", h, value)
@@ -129,15 +153,28 @@ module Fugit
129
153
 
130
154
  # piece parsers bottom to top
131
155
 
156
+ def am_pm(i)
157
+ rex(:am_pm, i, / *(am|pm)/i)
158
+ end
159
+
132
160
  def digital_hour(i)
133
161
  rex(:digital_hour, i, /(2[0-4]|[01][0-9]):?[0-5]\d/)
134
162
  end
163
+
164
+ def _simple_hour(i)
165
+ rex(:sh, i, /(2[0-4]|[01]?[0-9])/)
166
+ end
135
167
  def simple_hour(i)
136
- rex(:simple_hour, i, /(2[0-4]|[01]?[0-9])/)
168
+ seq(:simple_hour, i, :_simple_hour, :am_pm, '?')
169
+ end
170
+
171
+ def _numeral_hour(i)
172
+ rex(:nh, i, /(#{NUMS.join('|')})/i)
137
173
  end
138
174
  def numeral_hour(i)
139
- rex(:numeral_hour, i, /(#{NUMS.join('|')})/i)
175
+ seq(:numeral_hour, i, :_numeral_hour, :am_pm, '?')
140
176
  end
177
+
141
178
  def name_hour(i)
142
179
  rex(:name_hour, i, /(#{NHOURS.keys.join('|')})/i)
143
180
  end
@@ -170,7 +207,7 @@ module Fugit
170
207
  /ix)
171
208
  end
172
209
 
173
- def flag(i); rex(:flag, i, /(every|from|at|after|am|pm|on|in)/i); end
210
+ def flag(i); rex(:flag, i, /(every|from|at|after|on|in)/i); end
174
211
 
175
212
  def datum(i)
176
213
  alt(nil, i,
@@ -204,10 +241,6 @@ module Fugit
204
241
  [ k, [ tt.string.strip, EtOrbi.get_tzone(tt.string.strip) ] ]
205
242
  when :duration
206
243
  [ k, [ Fugit::Duration.parse(tt.string.strip) ] ]
207
- when :numeral_hour
208
- [ k, NUMS.index(v) ]
209
- when :simple_hour
210
- [ k, v.to_i ]
211
244
  when :digital_hour
212
245
  v = v.gsub(/:/, '')
213
246
  [ k, [ v[0, 2], v[2, 2] ] ]
@@ -217,6 +250,11 @@ module Fugit
217
250
  [ k, WEEKDAYS.index(v[0, 3]) ]
218
251
  when :day_range
219
252
  [ k, tt.subgather(nil).collect { |st| st.string.downcase } ]
253
+ when :numeral_hour, :simple_hour
254
+ vs = tt.subgather(nil).collect { |ttt| ttt.string.downcase.strip }
255
+ v = k == :simple_hour ? vs[0].to_i : NUMS.index(vs[0])
256
+ v += 12 if vs[1] == 'pm'
257
+ [ k, v ]
220
258
  else
221
259
  [ k, v ]
222
260
  end }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fugit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-16 00:00:00.000000000 Z
11
+ date: 2019-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: raabro