fugit 0.9.4 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a5457b3ed0c40bebd7f6725f5884ba0894f61c2c
4
- data.tar.gz: c1daf99e24e3d241d3ccd4bd591e308b487ecc13
3
+ metadata.gz: 614db4a7a2630eee78f008aa1a446ec9b59acfd1
4
+ data.tar.gz: 5325bc91f0aa055571b1c07f6e8e87357929898f
5
5
  SHA512:
6
- metadata.gz: 8ca834e48c23d1cabae7589ccf2292caf250bc0fc2e7fdaa8e4dd9a431ebf97d62aa08cbf2eacf178ae7cf97a816869b9caf023dfd0b24f0e30c55a56e232cf8
7
- data.tar.gz: e16216f72f97619d86c47c1be9502ff854785751091fd99b9829820bc087a260fdd60a02aef1a27ed12f6d0d5439bad361a99847b96f1d6d15d08a8a5dde1d71
6
+ metadata.gz: 5622b68c6eeec8702bb0a1cba25144c67905a3e92d839e22906192b9acecef71258810043b5ba30d3c8f76757f8adc9a9b60c2b233186bf3d7018e14c59fb00b
7
+ data.tar.gz: 7a0c9ff30fd795138f664f170d4998aeb981591349a34fe246a0c6b86ec02f33c830a8d9792b6582327723268514b3db1eda50c7d7a73581845f96ce37321e27
@@ -2,6 +2,12 @@
2
2
  # fugit CHANGELOG.md
3
3
 
4
4
 
5
+ ## fugit 0.9.5 released 2017-01-07
6
+
7
+ * Implement Fugit.determine_type(s)
8
+ * Rename core.rb to parse.rb
9
+
10
+
5
11
  ## fugit 0.9.4 released 2017-01-06
6
12
 
7
13
  * Accept cron strings with seconds
@@ -25,7 +25,7 @@
25
25
 
26
26
  module Fugit
27
27
 
28
- VERSION = '0.9.4'
28
+ VERSION = '0.9.5'
29
29
  end
30
30
 
31
31
  require 'time'
@@ -33,9 +33,9 @@ require 'stringio'
33
33
 
34
34
  require 'raabro'
35
35
 
36
- require 'fugit/core'
37
36
  require 'fugit/misc'
38
37
  require 'fugit/cron'
39
38
  require 'fugit/duration'
40
39
  require 'fugit/nat'
40
+ require 'fugit/parse'
41
41
 
@@ -67,6 +67,8 @@ module Fugit
67
67
  original = s
68
68
  s = SPECIALS[s] || s
69
69
 
70
+ return nil unless s.is_a?(String)
71
+
70
72
  #p s; Raabro.pp(Parser.parse(s, debug: 3))
71
73
  h = Parser.parse(s)
72
74
 
@@ -80,10 +82,10 @@ module Fugit
80
82
  parse(s) || fail(ArgumentError.new("not a cron string #{s.inspect}"))
81
83
  end
82
84
 
83
- class NextTime # TODO at some point, use ZoTime
85
+ class TimeCursor # TODO at some point, use ZoTime
84
86
 
85
87
  def initialize(t)
86
- @t = t.is_a?(NextTime) ? t.time : t
88
+ @t = t.is_a?(TimeCursor) ? t.time : t
87
89
  end
88
90
 
89
91
  def time; @t; end
@@ -173,7 +175,7 @@ module Fugit
173
175
 
174
176
  return true if @monthdays.nil?
175
177
 
176
- last = (NextTime.new(nt).inc_month.time - 24 * 3600).day + 1
178
+ last = (TimeCursor.new(nt).inc_month.time - 24 * 3600).day + 1
177
179
 
178
180
  @monthdays
179
181
  .collect { |d| d < 1 ? last + d : d }
@@ -194,7 +196,7 @@ module Fugit
194
196
  def match?(t)
195
197
 
196
198
  t = Fugit.do_parse_at(t)
197
- t = NextTime.new(t)
199
+ t = TimeCursor.new(t)
198
200
 
199
201
  month_match?(t) && day_match?(t) &&
200
202
  hour_match?(t) && min_match?(t) && sec_match?(t)
@@ -202,38 +204,38 @@ module Fugit
202
204
 
203
205
  def next_time(from=Time.now)
204
206
 
205
- nt = NextTime.new(from)
207
+ t = TimeCursor.new(from)
206
208
 
207
209
  loop do
208
- #p [ :l, Fugit.time_to_s(nt.time) ]
209
- (from.to_i == nt.to_i) && (nt.inc(1); next)
210
- month_match?(nt) || (nt.inc_month; next)
211
- day_match?(nt) || (nt.inc_day; next)
212
- hour_match?(nt) || (nt.inc_hour; next)
213
- min_match?(nt) || (nt.inc_min; next)
214
- sec_match?(nt) || (nt.inc_sec(@seconds); next)
210
+ #p [ :l, Fugit.time_to_s(t.time) ]
211
+ (from.to_i == t.to_i) && (t.inc(1); next)
212
+ month_match?(t) || (t.inc_month; next)
213
+ day_match?(t) || (t.inc_day; next)
214
+ hour_match?(t) || (t.inc_hour; next)
215
+ min_match?(t) || (t.inc_min; next)
216
+ sec_match?(t) || (t.inc_sec(@seconds); next)
215
217
  break
216
218
  end
217
219
 
218
- nt.time
220
+ t.time
219
221
  end
220
222
 
221
223
  def previous_time(from=Time.now)
222
224
 
223
- nt = NextTime.new(from)
225
+ t = TimeCursor.new(from)
224
226
 
225
227
  loop do
226
- #p [ :l, Fugit.time_to_s(nt.time) ]
227
- (from.to_i == nt.to_i) && (nt.inc(-1); next)
228
- month_match?(nt) || (nt.dec_month; next)
229
- day_match?(nt) || (nt.dec_day; next)
230
- hour_match?(nt) || (nt.dec_hour; next)
231
- min_match?(nt) || (nt.dec_min; next)
232
- sec_match?(nt) || (nt.dec_sec(@seconds); next)
228
+ #p [ :l, Fugit.time_to_s(t.time) ]
229
+ (from.to_i == t.to_i) && (t.inc(-1); next)
230
+ month_match?(t) || (t.dec_month; next)
231
+ day_match?(t) || (t.dec_day; next)
232
+ hour_match?(t) || (t.dec_hour; next)
233
+ min_match?(t) || (t.dec_min; next)
234
+ sec_match?(t) || (t.dec_sec(@seconds); next)
233
235
  break
234
236
  end
235
237
 
236
- nt.time
238
+ t.time
237
239
  end
238
240
 
239
241
  # Mostly used as a #next_time sanity check.
@@ -40,9 +40,11 @@ module Fugit
40
40
 
41
41
  original = s
42
42
 
43
- s = s
44
- #s = s.to_i if s.is_a?(Numeric)
45
- s = s.to_s.strip
43
+ s = s.to_s if s.is_a?(Numeric)
44
+
45
+ return nil unless s.is_a?(String)
46
+
47
+ s = s.strip
46
48
  s = s + 's' if s.match(/\A-?(\d*\.)?\d+\z/)
47
49
  #p [ original, s ]; Raabro.pp(Parser.parse(s, debug: 3))
48
50
 
@@ -32,6 +32,10 @@ module Fugit
32
32
 
33
33
  def self.parse(s)
34
34
 
35
+ return s if s.is_a?(Fugit::Cron) || s.is_a?(Fugit::Duration)
36
+
37
+ return nil unless s.is_a?(String)
38
+
35
39
  #p s; Raabro.pp(Parser.parse(s, debug: 3))
36
40
  a = Parser.parse(s)
37
41
 
@@ -45,6 +49,11 @@ module Fugit
45
49
  end
46
50
  end
47
51
 
52
+ def self.do_parse(s)
53
+
54
+ parse(s) || fail(ArgumentError.new("could not parse a nat #{s.inspect}"))
55
+ end
56
+
48
57
  def self.parse_cron(a)
49
58
 
50
59
  h = { min: nil, hou: [], dom: [ nil ], mon: [ nil ], dow: [ nil ] }
@@ -36,38 +36,41 @@ module Fugit
36
36
  Time.parse(s)
37
37
  end
38
38
 
39
- def self.parse_cron(s)
40
-
41
- ::Fugit::Cron.parse(s)
42
- end
43
-
44
- def self.do_parse_cron(s)
45
-
46
- ::Fugit::Cron.do_parse(s)
47
- end
39
+ def self.parse_cron(s); ::Fugit::Cron.parse(s); end
40
+ def self.parse_duration(s); ::Fugit::Duration.parse(s); end
41
+ def self.parse_in(s); parse_duration(s); end
42
+ def self.parse_nat(s); ::Fugit::Nat.parse(s); end
48
43
 
49
- def self.parse_duration(s)
44
+ def self.do_parse_cron(s); ::Fugit::Cron.do_parse(s); end
45
+ def self.do_parse_duration(s); ::Fugit::Duration.do_parse(s); end
46
+ def self.do_parse_in(s); do_parse_duration(s); end
47
+ def self.do_parse_nat(s); ::Fugit::Nat.do_parse(s); end
50
48
 
51
- ::Fugit::Duration.parse(s)
52
- end
49
+ def self.parse(s, opts={})
53
50
 
54
- def self.do_parse_duration(s)
51
+ opts[:at] = opts[:in] if opts.has_key?(:in)
55
52
 
56
- ::Fugit::Duration.do_parse(s)
53
+ (opts[:cron] != false && parse_cron(s)) ||
54
+ (opts[:duration] != false && parse_duration(s)) ||
55
+ (opts[:at] != false && parse_at(s)) ||
56
+ (opts[:nat] != false && parse_nat(s)) ||
57
+ nil
57
58
  end
58
59
 
59
- def self.parse_in(s); parse_duration(s); end
60
- def self.do_parse_in(s); do_parse_duration(s); end
61
-
62
- def self.parse(s)
60
+ def self.do_parse(s, opts={})
63
61
 
64
- parse_cron(s) || parse_duration(s) || parse_at(s)
62
+ parse(s, opts) ||
63
+ fail(ArgumentError.new("found no time information in #{s.inspect}"))
65
64
  end
66
65
 
67
- def self.do_parse(s)
66
+ def self.determine_type(s)
68
67
 
69
- parse(s) ||
70
- fail(ArgumentError.new("fugit found no time information in #{s}.inspect"))
68
+ case self.parse(s)
69
+ when ::Time then 'at'
70
+ when ::Fugit::Cron then 'cron'
71
+ when ::Fugit::Duration then 'in'
72
+ else nil
73
+ end
71
74
  end
72
75
  end
73
76
 
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
4
+ version: 0.9.5
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-06 00:00:00.000000000 Z
11
+ date: 2017-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: raabro
@@ -53,11 +53,11 @@ files:
53
53
  - README.md
54
54
  - fugit.gemspec
55
55
  - lib/fugit.rb
56
- - lib/fugit/core.rb
57
56
  - lib/fugit/cron.rb
58
57
  - lib/fugit/duration.rb
59
58
  - lib/fugit/misc.rb
60
59
  - lib/fugit/nat.rb
60
+ - lib/fugit/parse.rb
61
61
  homepage: http://github.com/floraison/fugit
62
62
  licenses:
63
63
  - MIT