fugit 0.9.2 → 0.9.3
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 +5 -0
- data/lib/fugit.rb +2 -1
- data/lib/fugit/core.rb +1 -1
- data/lib/fugit/cron.rb +13 -3
- data/lib/fugit/duration.rb +5 -0
- data/lib/fugit/nat.rb +152 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db0fd5566944d325bda3692e5ca32819d7f0b8d8
|
4
|
+
data.tar.gz: 226e4f9ad3e97a40c17619e9be38f2b2ff408c83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6af1fa57a2484c9c62a3a7f73a65be6d12b579501efdb3c479f8e1868d73afab2b8e544d9d7904834558bab5d6f93e2ce53588ba4a46e2c64868fe4255d77634
|
7
|
+
data.tar.gz: b3be693935fd379a0e9270194600bcfe2210b2bf3b969596b2f476285632729bf3f0e320029c8e398d1f524c240432acc5f15899d6ad1365c0cddd63297fa82f
|
data/CHANGELOG.md
CHANGED
data/lib/fugit.rb
CHANGED
data/lib/fugit/core.rb
CHANGED
data/lib/fugit/cron.rb
CHANGED
@@ -264,6 +264,8 @@ module Fugit
|
|
264
264
|
|
265
265
|
@original = original
|
266
266
|
|
267
|
+
h ||= {}
|
268
|
+
|
267
269
|
determine_minutes(h[:min])
|
268
270
|
determine_hours(h[:hou])
|
269
271
|
determine_monthdays(h[:dom])
|
@@ -302,28 +304,34 @@ module Fugit
|
|
302
304
|
end
|
303
305
|
|
304
306
|
def determine_minutes(mins)
|
307
|
+
return @minutes = nil unless mins
|
305
308
|
@minutes = mins.inject([]) { |a, r| a.concat(expand(0, 59, r)) }
|
306
309
|
compact(:@minutes)
|
307
310
|
end
|
308
311
|
|
309
312
|
def determine_hours(hous)
|
313
|
+
return @hours = nil unless hous
|
310
314
|
@hours = hous.inject([]) { |a, r| a.concat(expand(0, 23, r)) }
|
311
315
|
@hours = @hours.collect { |h| h == 24 ? 0 : h }
|
312
316
|
compact(:@hours)
|
313
317
|
end
|
314
318
|
|
315
319
|
def determine_monthdays(doms)
|
320
|
+
return @monthdays = nil unless doms
|
316
321
|
@monthdays = doms.inject([]) { |a, r| a.concat(expand(1, 31, r)) }
|
317
322
|
compact(:@monthdays)
|
318
323
|
end
|
319
324
|
|
320
325
|
def determine_months(mons)
|
326
|
+
return @months = nil unless mons
|
321
327
|
@months = mons.inject([]) { |a, r| a.concat(expand(1, 12, r)) }
|
322
328
|
compact(:@months)
|
323
329
|
end
|
324
330
|
|
325
331
|
def determine_weekdays(dows)
|
326
332
|
|
333
|
+
return @weekdays = nil unless dows
|
334
|
+
|
327
335
|
@weekdays = dows.inject([]) { |a, r|
|
328
336
|
aa = expand(0, 7, r)
|
329
337
|
if hsh = r[3]
|
@@ -346,7 +354,9 @@ module Fugit
|
|
346
354
|
|
347
355
|
module Parser include Raabro
|
348
356
|
|
349
|
-
WEEKDAYS = %w[
|
357
|
+
WEEKDAYS = %w[ sunday monday tuesday wednesday thursday friday saturday ]
|
358
|
+
WEEKDS = WEEKDAYS.collect { |d| d[0, 3] }
|
359
|
+
|
350
360
|
MONTHS = %w[ - jan feb mar apr may jun jul aug sep oct nov dec ]
|
351
361
|
|
352
362
|
# piece parsers bottom to top
|
@@ -362,7 +372,7 @@ module Fugit
|
|
362
372
|
def core_hou(i); rex(:hou, i, /(2[0-4]|[01]?[0-9])/); end
|
363
373
|
def core_dom(i); rex(:dom, i, /(-?(3[01]|[012]?[0-9])|last|l)/i); end
|
364
374
|
def core_mon(i); rex(:mon, i, /(1[0-2]|0?[0-9]|#{MONTHS[1..-1].join('|')})/i); end
|
365
|
-
def core_dow(i); rex(:dow, i, /([0-7]|#{
|
375
|
+
def core_dow(i); rex(:dow, i, /([0-7]|#{WEEKDS.join('|')})/i); end
|
366
376
|
|
367
377
|
def dow_hash(i); rex(:hash, i, /#(-?[1-5]|last|l)/i); end
|
368
378
|
|
@@ -424,7 +434,7 @@ module Fugit
|
|
424
434
|
s = t.string.downcase
|
425
435
|
|
426
436
|
(k == :mon && MONTHS.index(s)) ||
|
427
|
-
(k == :dow &&
|
437
|
+
(k == :dow && WEEKDS.index(s)) ||
|
428
438
|
(k == :dom && s[0, 1] == 'l' && -1) || # L, l, last
|
429
439
|
s.to_i
|
430
440
|
end
|
data/lib/fugit/duration.rb
CHANGED
data/lib/fugit/nat.rb
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2017-2017, John Mettraux, jmettraux+flor@gmail.com
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
# THE SOFTWARE.
|
21
|
+
#
|
22
|
+
# Made in Japan.
|
23
|
+
#++
|
24
|
+
|
25
|
+
|
26
|
+
module Fugit
|
27
|
+
|
28
|
+
# A natural language set of parsers for fugit.
|
29
|
+
# Focuses on cron expressions. The rest is better left to Chronic and friends.
|
30
|
+
#
|
31
|
+
module Nat
|
32
|
+
|
33
|
+
def self.parse(s)
|
34
|
+
|
35
|
+
#p s; Raabro.pp(Parser.parse(s, debug: 3))
|
36
|
+
a = Parser.parse(s)
|
37
|
+
|
38
|
+
#p a
|
39
|
+
return nil unless a
|
40
|
+
|
41
|
+
if a.include?([ :flag, 'every' ])
|
42
|
+
parse_cron(a)
|
43
|
+
else
|
44
|
+
nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.parse_cron(a)
|
49
|
+
|
50
|
+
h = { min: nil, hou: nil, dom: nil, mon: nil, dow: nil }
|
51
|
+
|
52
|
+
a.each do |key, val|
|
53
|
+
if key == :biz_day
|
54
|
+
h[:dow] = (1..5).to_a.collect { |wd| [ wd ] }
|
55
|
+
elsif key == :simple_hour || key == :numeral_hour
|
56
|
+
(h[:hou] ||= []) << val
|
57
|
+
elsif key == :digital_hour
|
58
|
+
h[:hou] = val[0, 1]
|
59
|
+
h[:min] = val[1, 1]
|
60
|
+
elsif key == :name_day
|
61
|
+
(h[:dow] ||= []) << [ val ]
|
62
|
+
elsif key == :flag && val == 'pm' && h[:hou]
|
63
|
+
h[:hou][-1] = h[:hou][-1] + 12
|
64
|
+
end
|
65
|
+
end
|
66
|
+
h[:min] ||= [ 0 ]
|
67
|
+
|
68
|
+
Fugit::Cron.allocate.send(:init, nil, h)
|
69
|
+
end
|
70
|
+
|
71
|
+
module Parser include Raabro
|
72
|
+
|
73
|
+
NUMS = %w[
|
74
|
+
zero
|
75
|
+
one two three four five six seven eight nine
|
76
|
+
ten eleven twelve ]
|
77
|
+
|
78
|
+
WEEKDAYS =
|
79
|
+
Fugit::Cron::Parser::WEEKDS + Fugit::Cron::Parser::WEEKDAYS
|
80
|
+
|
81
|
+
NHOURS =
|
82
|
+
{ 'noon' => [ 12, 0 ], 'midnight' => [ 0, 0 ] }
|
83
|
+
|
84
|
+
# piece parsers bottom to top
|
85
|
+
|
86
|
+
def digital_hour(i)
|
87
|
+
rex(:digital_hour, i, /(2[0-4]|[01][0-9]):?[0-5]\d/)
|
88
|
+
end
|
89
|
+
def simple_hour(i)
|
90
|
+
rex(:simple_hour, i, /(2[0-4]|[01]?[0-9])/)
|
91
|
+
end
|
92
|
+
def numeral_hour(i)
|
93
|
+
rex(:numeral_hour, i, /(#{NUMS.join('|')})/i)
|
94
|
+
end
|
95
|
+
def name_hour(i)
|
96
|
+
rex(:name_hour, i, /(#{NHOURS.keys.join('|')})/i)
|
97
|
+
end
|
98
|
+
def hour(i)
|
99
|
+
alt(nil, i, :numeral_hour, :name_hour, :digital_hour, :simple_hour);
|
100
|
+
end
|
101
|
+
|
102
|
+
def plain_day(i); rex(:plain_day, i, /day/i); end
|
103
|
+
def biz_day(i); rex(:biz_day, i, /(biz|business|week) *day/i); end
|
104
|
+
def name_day(i); rex(:name_day, i, /#{WEEKDAYS.reverse.join('|')}/i); end
|
105
|
+
|
106
|
+
def flag(i); rex(:flag, i, /(every|day|at|after|am|pm)/i); end
|
107
|
+
|
108
|
+
def datum(i)
|
109
|
+
alt(nil, i,
|
110
|
+
:flag,
|
111
|
+
:plain_day, :biz_day, :name_day,
|
112
|
+
:name_hour, :numeral_hour, :digital_hour, :simple_hour)
|
113
|
+
end
|
114
|
+
|
115
|
+
def sugar(i); rex(nil, i, /(and|or|[, \t]+)/i); end
|
116
|
+
|
117
|
+
def elt(i); alt(nil, i, :sugar, :datum); end
|
118
|
+
def nat(i); rep(:nat, i, :elt, 1); end
|
119
|
+
|
120
|
+
# rewrite parsed tree
|
121
|
+
|
122
|
+
def rewrite_nat(t)
|
123
|
+
|
124
|
+
#Raabro.pp(t)
|
125
|
+
t
|
126
|
+
.subgather(nil)
|
127
|
+
.collect { |tt|
|
128
|
+
|
129
|
+
k = tt.name
|
130
|
+
v = tt.string.downcase
|
131
|
+
|
132
|
+
case k
|
133
|
+
when :numeral_hour
|
134
|
+
[ k, NUMS.index(v) ]
|
135
|
+
when :simple_hour
|
136
|
+
[ k, v.to_i ]
|
137
|
+
when :digital_hour
|
138
|
+
v = v.gsub(/:/, '')
|
139
|
+
[ k, [ v[0, 2], v[2, 2] ] ]
|
140
|
+
when :name_hour
|
141
|
+
[ :digital_hour, NHOURS[v] ]
|
142
|
+
when :name_day
|
143
|
+
[ k, WEEKDAYS.index(v[0, 3]) ]
|
144
|
+
else
|
145
|
+
[ k, v ]
|
146
|
+
end
|
147
|
+
}
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
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: 0.9.
|
4
|
+
version: 0.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Mettraux
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: raabro
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- lib/fugit/cron.rb
|
58
58
|
- lib/fugit/duration.rb
|
59
59
|
- lib/fugit/misc.rb
|
60
|
+
- lib/fugit/nat.rb
|
60
61
|
homepage: http://github.com/floraison/fugit
|
61
62
|
licenses:
|
62
63
|
- MIT
|