reminders_txt 0.3.14 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/reminders_txt.rb +22 -171
- metadata +9 -9
- 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: 95e7b3c960ba713562c321978ec7569bb61eb03e
|
4
|
+
data.tar.gz: '09fa5e4699bcc944149c5e8e1d12961c0640fcc7'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9bcb76b37bc86a523553672e89d75fa46f106b5bbe3461085bad9fd926e786e53b54d71e7512cb8d06b47560ad677067c96285daeaaf233c1a5041022b84dec5
|
7
|
+
data.tar.gz: cd8823318b716e71f75e15080c90386a1b84584dc87214d5c031ad35292ec4e7076cc940968e0b4735462d739896be84016d7431f01568eaa036b373ef4b2fb6
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/reminders_txt.rb
CHANGED
@@ -4,40 +4,28 @@
|
|
4
4
|
|
5
5
|
|
6
6
|
require 'dynarex'
|
7
|
-
require '
|
7
|
+
require 'event_nlp'
|
8
8
|
require 'digest/md5'
|
9
|
-
require 'chronic_cron'
|
10
|
-
|
11
|
-
|
12
|
-
module Ordinals
|
13
|
-
|
14
|
-
refine Integer do
|
15
|
-
def ordinal
|
16
|
-
self.to_s + ( (10...20).include?(self) ? 'th' :
|
17
|
-
%w{ th st nd rd th th th th th th }[self % 10] )
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
9
|
|
23
10
|
|
24
11
|
class RemindersTxt
|
25
|
-
|
26
|
-
using Ordinals
|
12
|
+
|
27
13
|
|
28
14
|
attr_reader :reminders, :dx
|
29
15
|
|
30
16
|
def initialize(raw_s='reminders.txt', now: Time.now)
|
31
17
|
|
32
18
|
super()
|
33
|
-
|
19
|
+
|
34
20
|
@now = now
|
21
|
+
|
22
|
+
|
35
23
|
@filepath = raw_s
|
36
24
|
|
37
25
|
if raw_s.lines.length > 1 then
|
38
26
|
|
39
27
|
if raw_s.lstrip[0] == '<' then
|
40
|
-
|
28
|
+
|
41
29
|
@filepath = 'reminders.xml'
|
42
30
|
@dx = Dynarex.new raw_s
|
43
31
|
|
@@ -68,12 +56,11 @@ class RemindersTxt
|
|
68
56
|
|
69
57
|
def add(s)
|
70
58
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
@reminders <<
|
76
|
-
|
59
|
+
s.strip!
|
60
|
+
r = EventNlp.new(@now, params: {input: s}).parse(s)
|
61
|
+
return if r.nil?
|
62
|
+
|
63
|
+
@reminders << r
|
77
64
|
refresh()
|
78
65
|
|
79
66
|
end
|
@@ -95,160 +82,25 @@ class RemindersTxt
|
|
95
82
|
|
96
83
|
def to_xml()
|
97
84
|
@dx.to_xml pretty: true
|
98
|
-
end
|
99
|
-
|
100
|
-
protected
|
101
|
-
|
102
|
-
def expressions(params)
|
103
|
-
|
104
|
-
|
105
|
-
# some event every 2 weeks
|
106
|
-
# some event every 2 weeks at 6am starting from 14th Jan
|
107
|
-
# some event every 2 weeks at 6am starting from 18th Feb until 28th Oct
|
108
|
-
# some event every 2nd Monday (starting 7th Nov 2016)
|
109
|
-
# some event every 2nd Monday (starting 7th Nov until 3rd Dec)
|
110
|
-
|
111
|
-
|
112
|
-
starting = /(?:\(?\s*starting (\d+\w{2} \w+\s*\w*)(?: until (.*))?\s*\))?/
|
113
|
-
weekday = Date::DAYNAMES.join('|').downcase
|
114
|
-
months = (Date::MONTHNAMES[1..-1] + Date::ABBR_MONTHNAMES[1..-1])
|
115
|
-
.join('|').downcase
|
116
|
-
|
117
|
-
|
118
|
-
get /^(.*)(every \w+ \w+(?: at (\d+am) )?)\s*#{starting}/ do \
|
119
|
-
|title, recurring, time, raw_date, end_date|
|
120
|
-
|
121
|
-
input = params[:input]
|
122
|
-
|
123
|
-
d = Chronic.parse(raw_date)
|
124
|
-
|
125
|
-
if recurring =~ /day|week/ then
|
126
|
-
|
127
|
-
|
128
|
-
if d < @now then
|
129
|
-
|
130
|
-
new_date = CronFormat.new(ChronicCron.new(recurring)\
|
131
|
-
.to_expression, d).to_time
|
132
|
-
input.gsub!(raw_date, new_date\
|
133
|
-
.strftime("#{new_date.day.ordinal} %b %Y"))
|
134
|
-
d = new_date
|
135
|
-
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
|
140
|
-
#puts [0, title, recurring, time, raw_date, end_date].inspect
|
141
|
-
OpenStruct.new input: input, title: title, recurring: recurring,
|
142
|
-
date: d, end_date: end_date
|
143
|
-
|
144
|
-
end
|
145
|
-
|
146
|
-
# some meeting 3rd thursday of the month at 7:30pm
|
147
|
-
# some meeting First thursday of the month at 7:30pm
|
148
|
-
get /(.*)\s+(\w+ \w+day of (?:the|every) month at .*)/ do
|
149
|
-
|title, recurring|
|
150
|
-
|
151
|
-
#puts [1, title, recurring].inspect
|
152
|
-
OpenStruct.new input: params[:input], title: title, recurring: recurring
|
153
|
-
|
154
|
-
end
|
155
|
-
|
156
|
-
# hall 2 friday at 11am
|
157
|
-
get /(.*)\s+(#{weekday})\s+at\s+(.*)/i do |title, raw_day, time|
|
158
|
-
|
159
|
-
d = Chronic.parse(raw_day + ' ' + time)
|
160
|
-
|
161
|
-
#puts [1.5, title, raw_day].inspect
|
162
|
-
OpenStruct.new input: params[:input], title: title, date: d
|
163
|
-
|
164
|
-
end
|
165
|
-
|
166
|
-
# e.g. 21/05/2017 Forum meetup at Roundpeg from 2pm
|
167
|
-
get /^(\d+\/\d+\/\d+)\s+(.*)(?: from|at)\s+(\d+[ap]m)/ do
|
168
|
-
|raw_date, title, raw_time|
|
169
|
-
|
170
|
-
d = Chronic.parse(raw_date + ' ' +
|
171
|
-
raw_time, :endian_precedence => :little)
|
172
|
-
recurring = nil
|
173
|
-
|
174
|
-
#puts [3, title, raw_date].inspect
|
175
|
-
OpenStruct.new input: params[:input], title: title, date: d
|
176
|
-
end
|
177
|
-
|
178
|
-
# hall 2 friday at 11am
|
179
|
-
# some important day 24th Mar
|
180
|
-
|
181
|
-
with_date = "(.*)\\s+(\\d\+\s*(?:st|nd|rd|th)?\\s+(?:#{months}))"
|
182
|
-
alt_pattern = '([^\d]+)\s+(\d+[^\*]+)(\*)?'
|
183
|
-
|
184
|
-
get /#{with_date}|#{alt_pattern}\s*(\*)$/i do |title, raw_date, annualar|
|
185
|
-
|
186
|
-
d = Chronic.parse(raw_date)
|
187
|
-
|
188
|
-
recurring = nil
|
189
|
-
|
190
|
-
if annualar then
|
191
|
-
|
192
|
-
recurring = 'yearly'
|
193
|
-
if d < @now then
|
194
|
-
d = Chronic.parse(raw_date, now: Time.local(@now.year + 1, 1, 1))
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
#puts [2, title, raw_date].inspect
|
199
|
-
OpenStruct.new input: params[:input], title: title, date: d,
|
200
|
-
recurring: recurring
|
201
|
-
end
|
202
|
-
|
203
|
-
# 27-Mar@1436 some important day
|
204
|
-
get /(\d[^\s]+)\s+([^\*]+)(\*)?/ do |raw_date, title, annualar|
|
205
|
-
|
206
|
-
d = Chronic.parse(raw_date, :endian_precedence => :little)
|
207
|
-
recurring = nil
|
208
|
-
|
209
|
-
if annualar then
|
210
|
-
|
211
|
-
recurring = 'yearly'
|
212
|
-
if d < @now then
|
213
|
-
d = Chronic.parse(raw_date, now: Time.local(@now.year + 1, 1, 1))
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
|
-
|
218
|
-
#puts [3, title, raw_date].inspect
|
219
|
-
OpenStruct.new input: params[:input], title: title, date: d,
|
220
|
-
recurring: recurring
|
221
|
-
end
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
# e.g. 04-Aug@12:34
|
227
|
-
get '*' do |s|
|
228
|
-
puts 's: ' + s.inspect
|
229
|
-
'pattern unrecognised'
|
230
|
-
end
|
231
|
-
|
232
|
-
|
233
|
-
end
|
234
|
-
|
235
|
-
alias find_expression run_route
|
85
|
+
end
|
236
86
|
|
237
87
|
private
|
238
88
|
|
239
89
|
def import_txt(s)
|
240
90
|
|
241
91
|
@file_contents = s
|
242
|
-
@params = {}
|
243
|
-
expressions(@params)
|
244
92
|
buffer = s.lines[2..-1]
|
245
93
|
|
246
|
-
@reminders = buffer.inject([]) do |r, x|
|
94
|
+
@reminders = buffer.inject([]) do |r, x|
|
95
|
+
|
96
|
+
x.strip!
|
97
|
+
|
247
98
|
if (x.length > 1) then
|
248
|
-
|
249
|
-
rx =
|
250
|
-
r << rx
|
99
|
+
|
100
|
+
rx = EventNlp.new(@now, params: {input: x}).parse(x)
|
101
|
+
r << rx if rx
|
251
102
|
end
|
103
|
+
|
252
104
|
r
|
253
105
|
end
|
254
106
|
|
@@ -268,7 +120,7 @@ class RemindersTxt
|
|
268
120
|
if File.exists? @dxfilepath then
|
269
121
|
|
270
122
|
@dx = Dynarex.new @dxfilepath
|
271
|
-
|
123
|
+
|
272
124
|
@reminders.each do |reminder|
|
273
125
|
s = reminder.input
|
274
126
|
r = @dx.find_by_input s
|
@@ -317,7 +169,6 @@ class RemindersTxt
|
|
317
169
|
@reminders.each {|x| @dx.create x.to_h}
|
318
170
|
@dx.save @dxfilepath
|
319
171
|
|
320
|
-
end
|
321
|
-
|
172
|
+
end
|
322
173
|
|
323
174
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reminders_txt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -31,7 +31,7 @@ cert_chain:
|
|
31
31
|
n+SSd9dm8JjhZ2pqHtX+bgMZ18hrN06xfR+UPtk5BKC8v1PC0FWxaVR4lom39rFU
|
32
32
|
seDxJNsJgamAKg==
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date: 2017-05-
|
34
|
+
date: 2017-05-07 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: dynarex
|
@@ -42,7 +42,7 @@ dependencies:
|
|
42
42
|
version: '1.7'
|
43
43
|
- - ">="
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 1.7.
|
45
|
+
version: 1.7.21
|
46
46
|
type: :runtime
|
47
47
|
prerelease: false
|
48
48
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -52,9 +52,9 @@ dependencies:
|
|
52
52
|
version: '1.7'
|
53
53
|
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: 1.7.
|
55
|
+
version: 1.7.21
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
|
-
name:
|
57
|
+
name: event_nlp
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
60
|
- - "~>"
|
@@ -62,7 +62,7 @@ dependencies:
|
|
62
62
|
version: '0.1'
|
63
63
|
- - ">="
|
64
64
|
- !ruby/object:Gem::Version
|
65
|
-
version: 0.1.
|
65
|
+
version: 0.1.1
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
68
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -72,7 +72,7 @@ dependencies:
|
|
72
72
|
version: '0.1'
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.1.
|
75
|
+
version: 0.1.1
|
76
76
|
- !ruby/object:Gem::Dependency
|
77
77
|
name: chronic_cron
|
78
78
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,7 +82,7 @@ dependencies:
|
|
82
82
|
version: '0.3'
|
83
83
|
- - ">="
|
84
84
|
- !ruby/object:Gem::Version
|
85
|
-
version: 0.3.
|
85
|
+
version: 0.3.4
|
86
86
|
type: :runtime
|
87
87
|
prerelease: false
|
88
88
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -92,7 +92,7 @@ dependencies:
|
|
92
92
|
version: '0.3'
|
93
93
|
- - ">="
|
94
94
|
- !ruby/object:Gem::Version
|
95
|
-
version: 0.3.
|
95
|
+
version: 0.3.4
|
96
96
|
description:
|
97
97
|
email: james@jamesrobertson.eu
|
98
98
|
executables: []
|
metadata.gz.sig
CHANGED
Binary file
|