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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c2828bf125d6707c54707f45157f4b84972370fe
4
- data.tar.gz: 620ab55025dcebea9b332b4e2610631527659313
3
+ metadata.gz: 93a36077d24c8226afdf974f4054779549fb4ba8
4
+ data.tar.gz: 38f18eac702bda2136ccd787dee4ca3db41251a3
5
5
  SHA512:
6
- metadata.gz: 3012a5dccfb5a63d860a1b83dff62a331f903d470e34084a7f35fca2d47e3facf5a8615f5d0fd818e6fba7650e3015208b6754336fa41b20b0e623f3bf48bb31
7
- data.tar.gz: 320140191d5baffc8765ae2776e534a0b5f041f6e8bc315548d03969ebe011e6f79cd152366859e7486659e4eb2679159ac2905b646e7444919ed25ba2d25474
6
+ metadata.gz: 0ba8e3e2a0d4e1e07a52f5f6c994c8b1d7b4f28513114c0582a19d8420ea62acdc8a8e934a5473f26ee93e0780ae88faba3faaad9218fbbd8dcea3b7ba08b8dc
7
+ data.tar.gz: 7ea6c821a417e0e951c00959f9b7800ac7833ff8d0f1ea1bb2505f823dbb50ca5e55b2644d57530c4f2614ab33f694ac3f81647d670eebd623666c007fb24060
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
  # fugit CHANGELOG.md
3
3
 
4
4
 
5
+ ## fugit 0.9.2 released 2017-01-04
6
+
7
+ * Accept decimal places for duration seconds
8
+ * Alias Fugit .parse_in to .parse_duration
9
+
10
+
5
11
  ## fugit 0.9.1 released 2017-01-03
6
12
 
7
13
  * Implement Fugit::Duration #inflate and #deflate
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
@@ -25,7 +25,7 @@
25
25
 
26
26
  module Fugit
27
27
 
28
- VERSION = '0.9.1'
28
+ VERSION = '0.9.2'
29
29
  end
30
30
 
31
31
  require 'time'
data/lib/fugit/core.rb CHANGED
@@ -56,6 +56,9 @@ module Fugit
56
56
  ::Fugit::Duration.do_parse(s)
57
57
  end
58
58
 
59
+ def self.parse_in(s); parse_duration(s); end
60
+ def self.do_parse_in(s); do_parse_duration(s); end
61
+
59
62
  def self.parse(s)
60
63
 
61
64
  parse_duration(s) || parse_at(s) || parse_cron(s)
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
@@ -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-?\d+\z/)
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, /-?\d+ *(secs?|seconds?|s)/i); end
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
- def rewrite_dur(t)
298
+ # rewrite parsed tree
285
299
 
286
- t
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, /-?\d+S/); end
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
- def rewrite_dur(t)
327
+ # rewrite parsed tree
319
328
 
320
- t
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fugit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux