event_nlp 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/event_nlp.rb +36 -20
- data.tar.gz.sig +0 -0
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2747c0b8190818a48c2ecf2f046d36f149daac9
|
4
|
+
data.tar.gz: d4ac520028d38d04557bfe7b52ad114c633f26ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93b7a5cbcabea78ca1b64750de89fa7c59f537a0912d9bf29b84e53a7648f242429330a2de4ad27ca8830dd594ec48f945e8d5e5e4dcc911a37cdae1fffda93c
|
7
|
+
data.tar.gz: 8a397c27ed941cb479b2845fe19723b37f6ac9c4cd30b60b41314f7745482fc799e0bce1a1189441c8906ce1e65508745c5158bced0e5b2f985c7c7d0aadb0a4
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/event_nlp.rb
CHANGED
@@ -3,26 +3,50 @@
|
|
3
3
|
# file: event_nlp.rb
|
4
4
|
|
5
5
|
require 'chronic'
|
6
|
+
require 'ostruct'
|
6
7
|
require 'app-routes'
|
7
8
|
|
8
9
|
|
9
10
|
|
11
|
+
module Ordinals
|
12
|
+
|
13
|
+
refine Integer do
|
14
|
+
def ordinal
|
15
|
+
self.to_s + ( (10...20).include?(self) ? 'th' :
|
16
|
+
%w{ th st nd rd th th th th th th }[self % 10] )
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
10
22
|
class EventNlp
|
11
23
|
include AppRoutes
|
24
|
+
using Ordinals
|
12
25
|
|
26
|
+
attr_accessor :params
|
13
27
|
|
14
|
-
def initialize()
|
15
|
-
|
28
|
+
def initialize(now=Time.now, params: {})
|
29
|
+
|
16
30
|
super()
|
17
|
-
|
31
|
+
|
32
|
+
@now = now
|
33
|
+
@params = params
|
18
34
|
expressions(@params)
|
19
35
|
|
20
36
|
end
|
37
|
+
|
38
|
+
def parse(s)
|
39
|
+
|
40
|
+
r = run_route(s)
|
41
|
+
return unless r.is_a? Hash
|
42
|
+
|
43
|
+
OpenStruct.new({input: s}.merge r)
|
44
|
+
|
45
|
+
end
|
21
46
|
|
22
47
|
private
|
23
48
|
|
24
49
|
def expressions(params)
|
25
|
-
|
26
50
|
|
27
51
|
# some event every 2 weeks
|
28
52
|
# some event every 2 weeks at 6am starting from 14th Jan
|
@@ -31,7 +55,7 @@ class EventNlp
|
|
31
55
|
# some event every 2nd Monday (starting 7th Nov until 3rd Dec)
|
32
56
|
|
33
57
|
|
34
|
-
starting = /(?:\(?\s*starting (\d+\
|
58
|
+
starting = /(?:\(?\s*starting (\d+\w{2} \w+\s*\w*)(?: until (.*))?\s*\))?/
|
35
59
|
weekday = Date::DAYNAMES.join('|').downcase
|
36
60
|
months = (Date::MONTHNAMES[1..-1] + Date::ABBR_MONTHNAMES[1..-1])
|
37
61
|
.join('|').downcase
|
@@ -39,16 +63,15 @@ class EventNlp
|
|
39
63
|
|
40
64
|
get /^(.*)(every \w+ \w+(?: at (\d+am) )?)\s*#{starting}/ do \
|
41
65
|
|title, recurring, time, raw_date, end_date|
|
42
|
-
|
66
|
+
|
43
67
|
input = params[:input]
|
44
|
-
|
68
|
+
|
45
69
|
d = Chronic.parse(raw_date)
|
46
70
|
|
47
71
|
if recurring =~ /day|week/ then
|
48
|
-
|
49
|
-
|
72
|
+
|
50
73
|
if d < @now then
|
51
|
-
|
74
|
+
|
52
75
|
new_date = CronFormat.new(ChronicCron.new(recurring)\
|
53
76
|
.to_expression, d).to_time
|
54
77
|
input.gsub!(raw_date, new_date\
|
@@ -58,9 +81,9 @@ class EventNlp
|
|
58
81
|
end
|
59
82
|
end
|
60
83
|
|
61
|
-
|
62
84
|
#puts [0, title, recurring, time, raw_date, end_date].inspect
|
63
|
-
{title: title, recurring: recurring, date: d,
|
85
|
+
{input: input, title: title, recurring: recurring, date: d,
|
86
|
+
end_date: end_date}
|
64
87
|
|
65
88
|
end
|
66
89
|
|
@@ -139,19 +162,12 @@ class EventNlp
|
|
139
162
|
{ title: title, date: d, recurring: recurring }
|
140
163
|
end
|
141
164
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
165
|
# e.g. 04-Aug@12:34
|
146
166
|
get '*' do |s|
|
147
167
|
puts 's: ' + s.inspect
|
148
168
|
'pattern unrecognised'
|
149
169
|
end
|
150
170
|
|
151
|
-
|
152
171
|
end
|
153
172
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
end
|
173
|
+
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|