fugit 0.9.1 → 0.9.2
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +1 -1
- data/lib/fugit.rb +1 -1
- data/lib/fugit/core.rb +3 -0
- data/lib/fugit/cron.rb +4 -0
- data/lib/fugit/duration.rb +24 -22
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93a36077d24c8226afdf974f4054779549fb4ba8
|
4
|
+
data.tar.gz: 38f18eac702bda2136ccd787dee4ca3db41251a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ba8e3e2a0d4e1e07a52f5f6c994c8b1d7b4f28513114c0582a19d8420ea62acdc8a8e934a5473f26ee93e0780ae88faba3faaad9218fbbd8dcea3b7ba08b8dc
|
7
|
+
data.tar.gz: 7ea6c821a417e0e951c00959f9b7800ac7833ff8d0f1ea1bb2505f823dbb50ca5e55b2644d57530c4f2614ab33f694ac3f81647d670eebd623666c007fb24060
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -76,7 +76,7 @@ Example of cron strings understood by fugit:
|
|
76
76
|
|
77
77
|
## `Fugit::Duration`
|
78
78
|
|
79
|
-
A class `Fugit::Duration` to parse duration strings (vanilla [rufus-scheduler](https://github.com/jmettraux/rufus-scheduler) ones and [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) ones.
|
79
|
+
A class `Fugit::Duration` to parse duration strings (vanilla [rufus-scheduler](https://github.com/jmettraux/rufus-scheduler) ones and [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) ones).
|
80
80
|
|
81
81
|
Provides duration arithmetic tools.
|
82
82
|
|
data/lib/fugit.rb
CHANGED
data/lib/fugit/core.rb
CHANGED
data/lib/fugit/cron.rb
CHANGED
@@ -349,6 +349,8 @@ module Fugit
|
|
349
349
|
WEEKDAYS = %w[ sun mon tue wed thu fri sat ]
|
350
350
|
MONTHS = %w[ - jan feb mar apr may jun jul aug sep oct nov dec ]
|
351
351
|
|
352
|
+
# piece parsers bottom to top
|
353
|
+
|
352
354
|
def s(i); rex(:s, i, /[ \t]+/); end
|
353
355
|
def star(i); str(:star, i, '*'); end
|
354
356
|
def hyphen(i); str(nil, i, '-'); end
|
@@ -415,6 +417,8 @@ module Fugit
|
|
415
417
|
|
416
418
|
def cron(i); seq(:cron, i, :lmin_, :lhou_, :ldom_, :lmon_, :ldow); end
|
417
419
|
|
420
|
+
# rewriting the parsed tree
|
421
|
+
|
418
422
|
def to_i(k, t)
|
419
423
|
|
420
424
|
s = t.string.downcase
|
data/lib/fugit/duration.rb
CHANGED
@@ -41,9 +41,9 @@ module Fugit
|
|
41
41
|
original = s
|
42
42
|
|
43
43
|
s = s
|
44
|
-
s = s.to_i if s.is_a?(Numeric)
|
44
|
+
#s = s.to_i if s.is_a?(Numeric)
|
45
45
|
s = s.to_s.strip
|
46
|
-
s = s + 's' if s.match(/\A
|
46
|
+
s = s + 's' if s.match(/\A-?(\d*\.)?\d+\z/)
|
47
47
|
#p [ original, s ]; Raabro.pp(Parser.parse(s, debug: 3))
|
48
48
|
|
49
49
|
h =
|
@@ -263,8 +263,22 @@ module Fugit
|
|
263
263
|
self
|
264
264
|
end
|
265
265
|
|
266
|
+
def self.common_rewrite_dur(t)
|
267
|
+
|
268
|
+
t
|
269
|
+
.subgather(nil)
|
270
|
+
.inject({}) { |h, t|
|
271
|
+
v = t.string; v = v.index('.') ? v.to_f : v.to_i
|
272
|
+
# drops ending ("y", "m", ...) by itself
|
273
|
+
h[t.name] = (h[t.name] || 0) + v
|
274
|
+
h
|
275
|
+
}
|
276
|
+
end
|
277
|
+
|
266
278
|
module Parser include Raabro
|
267
279
|
|
280
|
+
# piece parsers bottom to top
|
281
|
+
|
268
282
|
def sep(i); rex(nil, i, /([ \t,]+|and)*/i); end
|
269
283
|
|
270
284
|
def yea(i); rex(:yea, i, /-?\d+ *y(ears?)?/i); end
|
@@ -274,27 +288,22 @@ module Fugit
|
|
274
288
|
def hou(i); rex(:hou, i, /-?\d+ *(hours?|h)/i); end
|
275
289
|
def min(i); rex(:min, i, /-?\d+ *(mins?|minutes?|m)/); end
|
276
290
|
|
277
|
-
def sec(i); rex(:sec, i,
|
291
|
+
def sec(i); rex(:sec, i, /-?((\d*\.)?\d+) *(secs?|seconds?|s)/i); end
|
278
292
|
# always last!
|
279
293
|
|
280
294
|
def elt(i); alt(nil, i, :yea, :mon, :wee, :day, :hou, :min, :sec); end
|
281
295
|
|
282
296
|
def dur(i); jseq(:dur, i, :elt, :sep); end
|
283
297
|
|
284
|
-
|
298
|
+
# rewrite parsed tree
|
285
299
|
|
286
|
-
|
287
|
-
.subgather(nil)
|
288
|
-
.inject({}) { |h, t|
|
289
|
-
h[t.name] = (h[t.name] || 0) + t.string.to_i
|
290
|
-
# drops ending ("y", "m", ...) by itself
|
291
|
-
h
|
292
|
-
}
|
293
|
-
end
|
300
|
+
def rewrite_dur(t); Fugit::Duration.common_rewrite_dur(t); end
|
294
301
|
end
|
295
302
|
|
296
303
|
module IsoParser include Raabro
|
297
304
|
|
305
|
+
# piece parsers bottom to top
|
306
|
+
|
298
307
|
def p(i); rex(nil, i, /P/); end
|
299
308
|
def t(i); rex(nil, i, /T/); end
|
300
309
|
|
@@ -304,7 +313,7 @@ module Fugit
|
|
304
313
|
def day(i); rex(:day, i, /-?\d+D/); end
|
305
314
|
def hou(i); rex(:hou, i, /-?\d+H/); end
|
306
315
|
def min(i); rex(:min, i, /-?\d+M/); end
|
307
|
-
def sec(i); rex(:sec, i,
|
316
|
+
def sec(i); rex(:sec, i, /-?(\d*\.)?\d+S/); end
|
308
317
|
|
309
318
|
def delt(i); alt(nil, i, :yea, :mon, :wee, :day); end
|
310
319
|
def telt(i); alt(nil, i, :hou, :min, :sec); end
|
@@ -315,16 +324,9 @@ module Fugit
|
|
315
324
|
|
316
325
|
def dur(i); seq(:dur, i, :p, :date, '?', :t_time, '?'); end
|
317
326
|
|
318
|
-
|
327
|
+
# rewrite parsed tree
|
319
328
|
|
320
|
-
|
321
|
-
.subgather(nil)
|
322
|
-
.inject({}) { |h, t|
|
323
|
-
h[t.name] = (h[t.name] || 0) + t.string.to_i
|
324
|
-
# drops ending ("y", "m", ...) by itself
|
325
|
-
h
|
326
|
-
}
|
327
|
-
end
|
329
|
+
def rewrite_dur(t); Fugit::Duration.common_rewrite_dur(t); end
|
328
330
|
end
|
329
331
|
end
|
330
332
|
end
|