event_nlp 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d9b15778895f2a01d0c3b972ba1436f9073fd6c
4
- data.tar.gz: 95eeb58ca3736fa353d0e961ce2f8d67b575d231
3
+ metadata.gz: f2747c0b8190818a48c2ecf2f046d36f149daac9
4
+ data.tar.gz: d4ac520028d38d04557bfe7b52ad114c633f26ea
5
5
  SHA512:
6
- metadata.gz: d284092bbd265392a53d4f137b89bb0b414589fe35f0e29a8ca61e1b895eafbb85207f81fd817ce94debe6a6a75bb2a59567e1ccd84f78301b4bddfc386ce6e4
7
- data.tar.gz: 7d2f3f486ff172b0704d474a15f5d3a94128958505f9c1573783d35fd4a20328c75a20b692fb81cdcf3d33d83ae3a337c485ae6749a9029f437e2c040bd3f33f
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
- @params = {}
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+\w2} \w+\s*\w*)(?: until (.*))?\s*\))?/
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, end_date: end_date}
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
- alias parse run_route
155
-
156
-
157
- end
173
+ 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.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file