event_nlp 0.5.4 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/lib/event_nlp.rb +229 -175
  4. data.tar.gz.sig +0 -0
  5. metadata +34 -34
  6. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f046c9ebbe0ea0e05075a6eaa38d6b5cf053d5072fc6a0ea7ec93d695f5ea449
4
- data.tar.gz: 51912d0dee9bf7c638ddb4b10946ad0f5ce560ed95398ab12a27ea417ae79391
3
+ metadata.gz: 34bd0366a4fd2bc97bf23dfaa4811bbf7b1add8b682c4a12133bacad71fe1126
4
+ data.tar.gz: d55983a0b2b70f388d1e1d06b0bf884d38c907c80045afe79c5542f346ecf864
5
5
  SHA512:
6
- metadata.gz: 5e093f418335b13bd36e811176d837caa7ad399d27f09f2d6f06cc057a08a91fd9c84bf19d6d7d8403b136f88ee37d99ee262c60df1285f96a3d205da83fc571
7
- data.tar.gz: 1bae302d138066d0913dc3cc7e272d233421faf44a06846e39742c5f09d4fc3cbf0ebd128ac2c002d3e030f8a99ed8bcb94a740ff617cb2eae8697cc905afe49
6
+ metadata.gz: be80fc3036e3944e2dd50bfa4efa8d63ddd0bc09093b10fd8d8504f79da261d59a020b0277d679142c6bd185faa9f18e16bddd89da11c7123a649de73aad57dc
7
+ data.tar.gz: d050f6ab6363fe62b40240a821ab4a6aaa554b78fba9d2ed9126581dc705bcf799cbce42cc24c8bdd6a8778c07d40762c457a460090e5f661f5af1c9c47b3e79
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/event_nlp.rb CHANGED
@@ -7,12 +7,11 @@ require 'ostruct'
7
7
  require 'app-routes'
8
8
 
9
9
 
10
-
11
10
  module Ordinals
12
11
 
13
12
  refine Integer do
14
13
  def ordinal
15
- self.to_s + ( (10...20).include?(self) ? 'th' :
14
+ self.to_s + ( self.between?(10,20) ? 'th' :
16
15
  %w{ th st nd rd th th th th th th }[self % 10] )
17
16
  end
18
17
  end
@@ -23,99 +22,153 @@ class EventNlp
23
22
  include AppRoutes
24
23
  using Ordinals
25
24
  using ColouredText
26
-
25
+
27
26
  attr_accessor :params
28
-
27
+
29
28
  def initialize(now=Time.now, params: {}, debug: false)
30
-
29
+
31
30
  super()
32
-
31
+
33
32
  @now = now
34
33
  @params = params
35
34
  expressions(@params)
36
35
  @debug = debug
37
36
 
38
37
  end
39
-
40
- def parse(s)
38
+
39
+ def parse(raws)
40
+
41
+ # catch irregular expressions and interpret them in advance
42
+ #
43
+ # e.g. Cafe meeting Thursday every 2 weeks =>
44
+ # Cafe meeting every 2nd Thursday
45
+ #
46
+ weekdays2 = (Date::DAYNAMES + Date::ABBR_DAYNAMES).join('|').downcase
47
+ pattern = /(?<day>#{weekdays2}) every (?<n>\d) weeks/i
48
+ found = raws.match(pattern)
49
+
50
+ s = if found then
51
+ s2 = "every %s %s" % [found[:n].to_i.ordinal, found[:day]]
52
+ raws.sub(pattern, s2)
53
+ else
54
+ raws
55
+ end
56
+
57
+ #-----------------------------------------------------------
41
58
 
42
59
  @params[:input] = s
43
60
  r = run_route(s)
44
61
 
45
62
  return unless r.is_a? Hash
46
-
63
+
47
64
  OpenStruct.new({input: s}.merge r)
48
-
49
- end
65
+
66
+ end
67
+
68
+ # returns an Array object of dates, projected from a recurring event
69
+ #
70
+ def project(s, year: Time.now.year)
71
+
72
+ r = parse s
73
+ dates = []
74
+ now = @now
75
+
76
+ while r.date.year == year.to_i do
77
+
78
+ dates << r.date
79
+ @now = r.date + 1
80
+ r = parse(r.input)
81
+
82
+ end
83
+
84
+ @now = now
85
+ return dates
86
+
87
+ end
50
88
 
51
89
  private
52
90
 
53
- def expressions(params)
91
+ def expressions(params)
54
92
 
55
93
  starting = /(?:\(?\s*starting (\d+\w{2} \w+\s*\w*)(?: until (.*))?\s*\))?/
56
- weekdays2 = (Date::DAYNAMES + Date::ABBR_DAYNAMES).join('|').downcase
94
+ weekdays2 = (Date::DAYNAMES + Date::ABBR_DAYNAMES).join('|').downcase
57
95
  weekdays = "(%s)" % weekdays2
58
96
  months = "(%s)" % (Date::MONTHNAMES[1..-1] + Date::ABBR_MONTHNAMES[1..-1])\
59
97
  .join('|').downcase
60
98
  times = /(?: *(?:at |@ |from )?(\d+(?::\d+)?(?:[ap]m|\b)) *)/
61
99
  times2 = /\d+(?::\d+)?[ap]m-\d+(?::\d+)?[ap]m|\d+(?::\d+)?-\d+(?::\d+)?/
62
- times3 = /(\d+(?::\d+)?[ap]m-\d+(?::\d+)?[ap]m|\d+(?::\d+)?-\d+(?::\d+)?)/
100
+ times3 = /(\d+(?::\d+)?[ap]m-\d+(?::\d+)?[ap]m|\d+(?::\d+)?-\d+(?::\d+)?)/
63
101
  days = /(\d+(?:st|nd|rd|th))/
64
102
  periods = /day|week|month/
65
-
103
+
66
104
  #weekdays = Date::DAYNAMES.join('|').downcase
67
105
  #
68
-
106
+
69
107
  #times = /(?: *at )?\d[ap]m/
70
108
 
71
- # e.g. electricity bill on the 28th of every month
109
+ # e.g. electricity bill on the 28th of every month
72
110
 
73
111
  get /(.*) on the (#{days}) of every (#{periods})/ do |title, day, recurring|
74
112
 
75
113
 
76
114
  raw_d = Chronic.parse(day)
77
-
115
+
78
116
  # if the date is less than now then increment it by a month
79
117
  d = raw_d < @now ? (raw_d.to_date >> 1).to_time : raw_d
80
-
81
-
118
+
119
+
82
120
  if @debug then
83
121
  puts [0.1, title, recurring, d].inspect.debug
84
122
  end
85
-
86
- {title: title, recurring: recurring, date: d}
87
-
123
+
124
+ {title: title, recurring: recurring, date: d}
125
+
88
126
  end
89
-
90
127
 
91
- get /^(.*)\s+(every \d\w+ \w+#{times})\s*#{starting}/ do \
128
+
129
+ get /^(.*)\s+(every \d\w+ \w+#{times}\s*#{starting})/ do \
92
130
  |title, recurring, time, raw_date, end_date|
93
131
 
94
- input = params[:input].clone
132
+ input = params[:input].clone
95
133
  d = Chronic.parse(raw_date + ' ' + time.to_s)
96
-
134
+
135
+ if @debug then
136
+ puts 'e300'
137
+ puts 'd: ' + d.inspect
138
+ puts 'recurring: ' + recurring.inspect
139
+ end
140
+
97
141
  if recurring =~ /day|week/ then
98
142
 
99
143
  if d < @now then
100
144
 
101
- new_date = CronFormat.new(ChronicCron.new(recurring)\
102
- .to_expression, d).to_time
145
+ cc = ChronicCron.new(recurring, d)
146
+ exp = cc.to_expression
147
+ puts 'exp: ' + exp.inspect if @debug
148
+
149
+ cf = CronFormat.new(exp, d)
150
+ cf.next until cf.to_time > @now
151
+
152
+ new_date = cf.to_time
153
+ puts 'new_date: ' + new_date.inspect if @debug
154
+
103
155
  input.gsub!(raw_date, new_date\
104
- .strftime("#{new_date.day.ordinal} %b %Y"))
156
+ .strftime("#{new_date.day.ordinal} %b %Y"))
105
157
  d = new_date
106
-
158
+
107
159
  end
108
160
  end
109
-
161
+
110
162
  if @debug then
111
- puts ["0.2".highlight, input, title, recurring, time, raw_date, end_date].inspect.debug
163
+ puts 'd: ' + d.inspect
164
+ puts ["0.2", input, title, recurring, time, raw_date, end_date].inspect.debug
112
165
  end
113
-
114
- {input: input, title: title, recurring: recurring, date: d,
115
- end_date: end_date}
116
-
166
+
167
+ {input: input, title: title, recurring: recurring, date: d,
168
+ end_date: end_date}
169
+
117
170
  end
118
-
171
+
119
172
  # e.g. some event 1st Monday of every month (starting 3rd Jul 2017)
120
173
 
121
174
  get /^(.*)\s+(\d(?:st|nd|rd|th) \w+ of every \w+(?: at (\d+[ap]m) )?)\s*#{starting}/ do \
@@ -123,55 +176,56 @@ class EventNlp
123
176
 
124
177
  input = params[:input].clone
125
178
  d = Chronic.parse(raw_date)
126
-
127
- if recurring =~ /day|week|month/ then
128
-
179
+
180
+ if recurring =~ /day|week|month/ then
181
+
129
182
  if d < @now then
130
183
 
131
184
  new_date = CronFormat.new(ChronicCron.new(recurring)\
132
185
  .to_expression, d).to_time
133
186
  input.gsub!(raw_date, new_date\
134
- .strftime("#{new_date.day.ordinal} %b %Y"))
187
+ .strftime("#{new_date.day.ordinal} %b %Y"))
135
188
  d = new_date
136
189
  else
137
190
  d = ChronicCron.new(recurring, d.to_date.to_time).to_time
138
191
  end
139
192
  end
140
-
193
+
141
194
  puts ['0.3'.highlight, title, recurring, time, raw_date, end_date].inspect.debug if @debug
142
- {input: input, title: title, recurring: recurring, date: d, end_date:
195
+ {input: input, title: title, recurring: recurring, date: d, end_date:
143
196
  end_date}
144
-
145
- end
197
+
198
+ end
146
199
 
147
200
  # some event every 2 weeks
148
201
  # some event every 2 weeks at 6am starting from 14th Jan
149
202
  # some event every 2 weeks at 6am starting from 18th Feb until 28th Oct
150
203
  # some event every 2nd Monday (starting 7th Nov 2016)
151
- # some event every 2nd Monday (starting 7th Nov until 3rd Dec)
204
+ # some event every 2nd Monday (starting 7th Nov until 3rd Dec)
152
205
  # some event every 2 weeks (starting 02/11/17)
153
206
  # some event every Wednesday 1pm-4pm
154
207
  #
155
208
  get /^(.*)(every .*)/ do |title, recurring|
156
209
 
157
210
  input = params[:input].clone
211
+ puts 'recurring: ' + recurring.inspect if @debug
158
212
  raw_start_date = recurring[/(?<=starting )[^\)]+/]
159
-
213
+
160
214
  d = if raw_start_date then
161
- start_date = Chronic.parse(raw_start_date, now: @now - 1,
215
+ start_date = Chronic.parse(raw_start_date, now: @now - 1,
162
216
  :endian_precedence => :little)
163
217
 
164
218
  puts ('recurring: ' + recurring.inspect).debug if @debug
165
219
  puts ('start_date: ' + start_date.inspect).debug if @debug
166
-
220
+
167
221
  if @now > start_date then
168
222
  exp = ChronicCron.new(recurring, start_date, debug: @debug).to_expression
169
223
  puts 'exp: ' + exp.inspect if @debug
170
-
224
+
171
225
  cf = CronFormat.new(exp, start_date, debug: @debug)
172
226
  puts ('cf.to_time: ' + cf.to_time.inspect).debug if @debug
173
227
  cf.next until cf.to_time > start_date
174
-
228
+
175
229
  new_date = cf.to_time
176
230
  input.gsub!(/(?<=starting )[^\)]+/, new_date\
177
231
  .strftime("#{new_date.day.ordinal} %b %Y"))
@@ -180,208 +234,208 @@ class EventNlp
180
234
  else
181
235
  start_date
182
236
  end
183
-
237
+
184
238
  else
185
239
  exp = ChronicCron.new(recurring).to_expression
186
240
  cf = CronFormat.new(exp, @now)
187
241
  cf.to_time
188
242
  end
189
-
190
243
 
191
-
244
+
245
+
192
246
  if recurring =~ /-/ then
193
- end_date = Chronic.parse d.to_date.to_s + ' ' +
194
- recurring[/(?<=-)\d+(?::\d+)?(?:[ap]m)?/]
247
+ end_date = Chronic.parse d.to_date.to_s + ' ' +
248
+ recurring[/(?<=-)\d+(?::\d+)?(?:[ap]m)?/]
195
249
  end
196
-
250
+
197
251
  puts ['0.5'.highlight, title, recurring, d].join("\n").debug if @debug
198
- {input: input, title: title.rstrip, recurring: recurring,
252
+ {input: input, title: title.rstrip, recurring: recurring,
199
253
  date: d, end_date: end_date }
200
-
201
- end
202
-
254
+
255
+ end
256
+
203
257
  # some meeting 3rd thursday of the month at 7:30pm
204
258
  # some meeting First thursday of the month at 7:30pm
205
- get /(.*)\s+(\w+ \w+day of (?:the|every) month at .*)/ do
259
+ get /(.*)\s+(\w+ \w+day of (?:the|every) month at .*)/ do
206
260
  |title, recurring|
207
261
 
208
262
  puts ['1'.highlight, title, recurring].inspect.debug if @debug
209
263
  { title: title, recurring: recurring }
210
264
 
211
265
  end
212
-
213
-
266
+
267
+
214
268
  # 7th Oct Euston Station (meet at Timothy's house at 7pm)
215
269
  get /^(\d(?:st|nd|rd|th) \w+) *(.*)\s+at\s+(\w+)/i do \
216
270
  |raw_day, title, time|
217
-
271
+
218
272
  d = Chronic.parse(raw_day + ' ' + time)
219
-
273
+
220
274
  puts ['1.5'.highlight, title, raw_day, time].inspect.debug if @debug
221
275
  { title: title, date: d }
222
-
223
- end
276
+
277
+ end
224
278
 
225
279
  # some event Wednesday
226
280
  # some event Wednesday 11am
227
-
281
+
228
282
  relative_day = '|today|tomorrow|tonight'
229
283
  get /^(.*)\s+(#{weekdays2+relative_day}\b)(?: \(([^\)]+)\)) (at \d{1,2}(?::\d{2})?(?:[ap]m)?)/i \
230
284
  do |title, raw_date, date2, time2|
231
285
  puts ('time2: ' + time2.inspect).debug if @debug
232
286
  puts ('date2: ' + date2).debug if @debug
233
287
  puts ('raw_date: ' + raw_date).debug if @debug
234
-
288
+
235
289
  d = if date2 then
236
290
  Chronic.parse(date2 + ' '+ time2.to_s)
237
291
  else
238
292
  Chronic.parse(raw_date + ' '+ time2)
239
293
  end
240
-
294
+
241
295
  puts ['4'.highlight, title, raw_date, date2, time2].inspect.debug if @debug
242
296
  {title: title, date: d }
243
-
297
+
244
298
  end
245
-
299
+
246
300
  # Group meeting Red Hall 2pm-4pm on Monday (4th Dec 2017)
247
301
  get /^(.*)\s+(#{times2})(?: on) +#{weekdays}\b(?: \(([^\)]+)\))?/i \
248
302
  do |title, xtimes, raw_day, actual_date|
249
-
303
+
250
304
  if @debug then
251
305
  puts ('actual_date: ' + actual_date.inspect).debug
252
306
  puts ('raw_day: ' + raw_day.inspect).debug
253
307
  puts ('xtimes: ' + xtimes.inspect).debug
254
308
  end
255
-
309
+
256
310
  input = params[:input].clone
257
-
311
+
258
312
  if actual_date then
259
313
  d = Chronic.parse actual_date
260
314
  else
261
- d = Chronic.parse(raw_day)
315
+ d = Chronic.parse(raw_day)
262
316
  input.sub!(/#{weekdays}\b/i,
263
- %Q(#{raw_day} (#{d.strftime("#{d.day.ordinal} %b %Y")})))
317
+ %Q(#{raw_day} (#{d.strftime("#{d.day.ordinal} %b %Y")})))
264
318
  end
265
319
 
266
320
  t1, t2 = xtimes.split(/-/,2)
267
-
321
+
268
322
  puts ('d: ' + d.inspect).debug if @debug
269
323
 
270
324
  d1, d2 = [t1, t2].map {|t| Chronic.parse([d.to_date.to_s, t].join(' ')) }
271
-
325
+
272
326
  puts ['4.65'.highlight, input, title, raw_day, d1, d2].inspect.debug if @debug
273
-
327
+
274
328
  {input: input, title: title, date: d1, end_date: d2 }
275
-
276
- end
277
-
329
+
330
+ end
331
+
278
332
  # hall 2 friday at 11am
279
333
 
280
334
  get /^(.*)\s+#{weekdays}\b(?: \(([^\)]+)\))?(#{times})?/i \
281
335
  do |title, raw_day, actual_date, time|
282
-
336
+
283
337
  if @debug then
284
338
  puts ('actual_date: ' + actual_date.inspect).debug
285
339
  puts ('raw_day: ' + raw_day.inspect).debug
286
340
  puts ('time: ' + time.inspect).debug
287
341
  end
288
-
342
+
289
343
  input = params[:input].clone
290
-
344
+
291
345
  if actual_date then
292
346
  d = Chronic.parse(raw_day + ' ' + time.to_s)
293
347
  else
294
- d = Chronic.parse(raw_day + ' ' + time.to_s)
348
+ d = Chronic.parse(raw_day + ' ' + time.to_s)
295
349
  input.sub!(/#{weekdays}/i,
296
- %Q(#{raw_day} (#{d.strftime("#{d.day.ordinal} %b %Y")})))
350
+ %Q(#{raw_day} (#{d.strftime("#{d.day.ordinal} %b %Y")})))
297
351
  end
298
-
352
+
299
353
  puts ('d: ' + d.inspect).debug if @debug
300
-
354
+
301
355
  puts [1.7, input, title, raw_day].inspect.debug if @debug
302
-
356
+
303
357
  {input: input, title: title, date: d }
304
-
305
- end
306
-
307
-
358
+
359
+ end
360
+
361
+
308
362
  # e.g. 21/05/2017 Forum meetup at Roundpeg from 2pm
309
- get /^(\d+\/\d+\/\d+)\s+(.*)(?: from|at)\s+(\d+[ap]m)/ do
363
+ get /^(\d+\/\d+\/\d+)\s+(.*)(?: from|at)\s+(\d+[ap]m)/ do
310
364
  |raw_date, title, raw_time|
311
-
312
- d = Chronic.parse(raw_date + ' ' +
365
+
366
+ d = Chronic.parse(raw_date + ' ' +
313
367
  raw_time, :endian_precedence => :little)
314
- recurring = nil
315
-
368
+ recurring = nil
369
+
316
370
  puts [3, title, raw_date].inspect.debug if @debug
317
371
  { title: title, date: d }
318
- end
319
-
372
+ end
373
+
320
374
  # friday hall 2 11am until 12am
321
375
  get /^#{weekdays}\s+(.*)\s+#{times} until #{times}$/i do \
322
376
  |raw_day, title, start_time, end_time|
323
-
377
+
324
378
  venue = title[/^at +(.*)/,1]
325
379
  d = Chronic.parse(raw_day + ' ' + start_time)
326
380
  d2 = Chronic.parse(raw_day + ' ' + end_time)
327
-
381
+
328
382
  puts ['1.44.3', title, raw_day].inspect.debug if @debug
329
383
  { title: title, date: d, end_date: d2, venue: venue }
330
-
331
- end
332
-
384
+
385
+ end
386
+
333
387
  # friday hall 2 11am
334
388
  get /^#{weekdays}\b\s+(.*)\s+(\d+(?::\d{2})?[ap]m)$/i do \
335
389
  |raw_day, title, time|
336
-
390
+
337
391
  puts [raw_day, title, time].inspect if @debug
338
392
  venue = title[/^at +(.*)/,1]
339
393
  d = Chronic.parse(raw_day + ' ' + time)
340
-
394
+
341
395
  puts [1.44, title, raw_day].inspect.debug if @debug
342
396
  { title: title, date: d, venue: venue }
343
-
344
- end
397
+
398
+ end
345
399
 
346
400
  # Tuesday 10th July hall 2 at 11am
347
401
  get /#{weekdays}\b\s+#{days}\s+#{months}\s+(?:at )?(.*)\s+at\s+(#{times})/i \
348
402
  do |wday, day, month, title, time|
349
-
403
+
350
404
  d = Chronic.parse([day, month, time].join(' '))
351
-
405
+
352
406
  puts ['1.44.5', day, month, title].inspect.debug if @debug
353
407
  { title: title, date: d }
354
-
355
- end
356
-
357
-
358
-
359
-
408
+
409
+ end
410
+
411
+
412
+
413
+
360
414
  # 27-Mar@1436 some important day
361
415
  # 25/07/2017 11pm some important day
362
416
  #
363
417
  get /^(\d+\/\d+\/\d+)\s*(\d+(?:\:\d+)?[ap]m)?\s+([^\*]+)(\*)?/ \
364
418
  do |raw_date, time, title, annualar|
365
419
 
366
- d = Chronic.parse(raw_date + ' ' + time.to_s,
420
+ d = Chronic.parse(raw_date + ' ' + time.to_s,
367
421
  :endian_precedence => :little)
368
422
  recurring = nil
369
-
423
+
370
424
  if annualar then
371
-
425
+
372
426
  recurring = 'yearly'
373
427
  if d < @now then
374
- d = Chronic.parse(raw_date, now: Time.local(@now.year + 1, 1, 1))
428
+ d = Chronic.parse(raw_date, now: Time.local(@now.year + 1, 1, 1))
375
429
  end
376
430
  end
377
-
378
-
431
+
432
+
379
433
  puts [3, title, raw_date, time].inspect.debug if @debug
380
434
  { title: title, date: d, recurring: recurring }
381
435
  end
382
436
 
383
437
 
384
-
438
+
385
439
  # Some event (10 Woodhouse Lane) 30th Nov from 9:15-17:00
386
440
 
387
441
  get /^(.*) #{days} #{months}(?: from)? (#{times2})/i do \
@@ -396,7 +450,7 @@ class EventNlp
396
450
 
397
451
  { title: title, date: d1, end_date: d2 }
398
452
  end
399
-
453
+
400
454
  # Some event (10 Woodhouse Lane) 30th Nov from 9:15-17:00
401
455
 
402
456
  get /^#{weekdays}\b #{months} #{days} #{times3} (.*)/i do \
@@ -411,7 +465,7 @@ class EventNlp
411
465
  puts [4.55, title, d1, d2].inspect.debug if @debug
412
466
 
413
467
  { title: title, date: d1, end_date: d2 }
414
- end
468
+ end
415
469
 
416
470
  # e.g. Wednesday 30th Nov at 9:15 10 Woodhouse Lane
417
471
 
@@ -423,8 +477,8 @@ class EventNlp
423
477
  puts [4.6, title, d1].inspect.debug if @debug
424
478
 
425
479
  { title: title, date: d1 }
426
- end
427
-
480
+ end
481
+
428
482
  # Some event (10 Woodhouse Lane) 30th Nov at 9:15-
429
483
 
430
484
  get /^(.*) #{days} #{months}(?: at)? (#{times})/i do \
@@ -441,73 +495,73 @@ class EventNlp
441
495
  # hall 2 at 11am
442
496
  #
443
497
  get /(.*)\s+at\s+(#{times})/i do |title, time|
444
-
498
+
445
499
  d = Chronic.parse(time)
446
-
500
+
447
501
  puts [1.45, title].inspect.debug if @debug
448
502
  { title: title, date: d }
449
-
450
- end
451
-
452
-
503
+
504
+ end
505
+
506
+
453
507
  # Council Tax on the last day of the month
454
508
  #
455
509
  get /^(.*) (?:o[nf] the)\s*last day of the month/i do |title|
456
-
510
+
457
511
  td = @now.to_date
458
512
  d = Date.civil(td.year, td.month, -1).to_time
459
-
513
+
460
514
  puts [5, title].inspect.debug if @debug
461
515
  { title: title, date: d }
462
-
463
- end
464
-
516
+
517
+ end
518
+
465
519
  # Council Tax last day of the month
466
520
  #
467
521
  get /^(.*) +last day of the month/i do |title|
468
-
522
+
469
523
  td = @now.to_date
470
524
  d = Date.civil(td.year, td.month, -1).to_time
471
-
525
+
472
526
  puts [5.1, title].inspect.debug if @debug
473
527
  { title: title, date: d }
474
-
475
- end
476
-
528
+
529
+ end
530
+
477
531
  # some important day 11 Oct *
478
532
  #
479
533
  get /^(.*) +(\d+) +#{months} *(\*)?/i \
480
534
  do |title, day, month, annualar|
481
-
535
+
482
536
  raw_date = day + ' ' + month
483
537
 
484
- d = Chronic.parse(raw_date,
538
+ d = Chronic.parse(raw_date,
485
539
  :endian_precedence => :little)
486
540
  recurring = nil
487
-
541
+
488
542
  if annualar then
489
-
543
+
490
544
  recurring = 'yearly'
491
545
  if d < @now then
492
- d = Chronic.parse(raw_date,
493
- now: Time.local(@now.year + 1, 1, 1))
546
+ d = Chronic.parse(raw_date,
547
+ now: Time.local(@now.year + 1, 1, 1))
494
548
  end
495
549
  end
496
-
497
-
550
+
551
+
498
552
  puts [6, title, raw_date].inspect.debug if @debug
499
553
  { title: title, date: d, recurring: recurring }
500
554
  end
501
-
502
-
503
-
555
+
556
+
557
+
504
558
  # Tuesday 3rd October gas service at Barbara's house morning 9am-1pm
505
559
  #
506
560
  get '*' do
507
-
561
+
508
562
  s = params[:input]
509
-
510
- time1, time2, month, weekday, day, end_date, annualar = nil, nil, nil,
563
+
564
+ time1, time2, month, weekday, day, end_date, annualar = nil, nil, nil,
511
565
  nil, nil, nil, false
512
566
 
513
567
  s2 = s.sub(/#{times}/i) {|x| time1 = x; ''}
@@ -522,29 +576,29 @@ class EventNlp
522
576
  raw_date = [day, month].compact.join(' ')
523
577
  raw_date = weekday if raw_date.empty?
524
578
 
525
- d = Chronic.parse(raw_date + ' ' + time1.to_s,
579
+ d = Chronic.parse(raw_date + ' ' + time1.to_s,
526
580
  :endian_precedence => :little, now: @now)
527
-
581
+
528
582
  if time2 then
529
- end_date = Chronic.parse(raw_date + ' ' + time2.to_s,
583
+ end_date = Chronic.parse(raw_date + ' ' + time2.to_s,
530
584
  :endian_precedence => :little)
531
585
  end
532
-
586
+
533
587
  recurring = nil
534
-
588
+
535
589
  if annualar then
536
-
590
+
537
591
  recurring = 'yearly'
538
592
  if d < @now then
539
- d = Chronic.parse(raw_date, now: Time.local(@now.year + 1, 1, 1))
593
+ d = Chronic.parse(raw_date, now: Time.local(@now.year + 1, 1, 1))
540
594
  end
541
- end
542
-
595
+ end
596
+
543
597
  puts [10, title, raw_date, time1].inspect.debug if @debug
544
598
  { title: title, date: d, end_date: end_date, recurring: recurring }
545
- end
546
-
547
-
599
+ end
600
+
601
+
548
602
  end
549
-
603
+
550
604
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: event_nlp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -11,52 +11,52 @@ cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
13
  MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
14
- YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMTkwOTEwMjE1ODM4WhcN
15
- MjAwOTA5MjE1ODM4WjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
16
- cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQDIK9mI
17
- 2ehHbT3MWV/EVo9LjVfNUu90FCb3R2C80G73/zGCDQKg2QaV00GUEV3c6T9ylg87
18
- p9k71VIoRrTzc4wkrwIKAQnJGWOd/6iDQIIoGd1VU2NYaE/ANfAiNTnktKyYu9U8
19
- oWkC+jsuCFlgsf97LbV0a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U1/n7Vs0
29
+ uAMg5MVU/jIEFCnynXZMmJwzN3r972rkjxj9mn6DGnVu1YI1IAohMwls5BVPm4/V
30
+ HgOsV5YFOzfJpThCqVzo3HwkqZWoO7LEgIIHJ/3UYnCfWM6uHmDuyOTLnCHL+lVD
31
+ 1pi26mG34ViOfEQzgW6HwswixuUQ4LI2eYtzyKIS3qAYEVm7UwujdbKghEycFKdF
32
+ sBJVdzARYZGMbrKm8dWeBWrMhW+Fdy8HlN0D4XMYmCIYghZ5XiOICaTlv4rYOkr8
33
+ sThE7E1FNUonatzkBVmSDlJZ6K0nBZLy3RKC48BP8SnSM/LtQe9atiiJBPOAOck3
34
+ yjnIKndZd6EKQ2X55kjrO1J+/2tqfMOUjH8/pJLmeeR8xV5+oAz65qpFx8FZOFPC
35
+ w8lJ+I6Lqqr5GpsweOnEHW4w200sMRD40u8qmGHrqirihL2KrwTD6A9UObvA5AxZ
36
+ 4Z4EPvKg+3jsK9Gv3GGSLdrD
37
37
  -----END CERTIFICATE-----
38
- date: 2019-09-10 00:00:00.000000000 Z
38
+ date: 2022-04-01 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: chronic_cron
42
42
  requirement: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: 0.5.0
47
44
  - - "~>"
48
45
  - !ruby/object:Gem::Version
49
- version: '0.5'
46
+ version: '0.7'
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 0.7.1
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- version: 0.5.0
57
54
  - - "~>"
58
55
  - !ruby/object:Gem::Version
59
- version: '0.5'
56
+ version: '0.7'
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 0.7.1
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: app-routes
62
62
  requirement: !ruby/object:Gem::Requirement
@@ -78,7 +78,7 @@ dependencies:
78
78
  - !ruby/object:Gem::Version
79
79
  version: 0.1.19
80
80
  description:
81
- email: james@jamesrobertson.eu
81
+ email: digital.robertson@gmail.com
82
82
  executables: []
83
83
  extensions: []
84
84
  extra_rdoc_files: []
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  - !ruby/object:Gem::Version
104
104
  version: '0'
105
105
  requirements: []
106
- rubygems_version: 3.0.1
106
+ rubygems_version: 3.2.22
107
107
  signing_key:
108
108
  specification_version: 4
109
109
  summary: 'Parses a calendar event for date, time, and description e.g. hall 2 friday
metadata.gz.sig CHANGED
Binary file