tickle 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +54 -106
- data/VERSION +1 -1
- data/lib/tickle/handler.rb +6 -1
- data/lib/tickle/tickle.rb +1 -0
- data/lib/tickle.rb +1 -1
- data/test/test_parsing.rb +1 -2
- data/tickle.gemspec +1 -1
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -8,7 +8,7 @@ Tickle is a natural language parser for recurring events.
|
|
8
8
|
|
9
9
|
Tickle is designed to be a compliment of Chronic and can interpret things such as "every 2 days, every Sunday, Sundays, Weekly, etc."
|
10
10
|
|
11
|
-
Tickle has one main method, "Tickle.parse," which returns
|
11
|
+
Tickle has one main method, "Tickle.parse," which returns the next time the event should occur, at which point you simply call Tickle.parse again.
|
12
12
|
|
13
13
|
-- INSTALLATION
|
14
14
|
|
@@ -23,15 +23,18 @@ Everything's at Github - http://github.com/noctivityinc/tickle
|
|
23
23
|
-- DEPENDENCIES
|
24
24
|
|
25
25
|
chronic gem (gem install chronic)
|
26
|
+
|
26
27
|
thoughtbot's shoulda (gem install shoulda)
|
27
28
|
|
28
29
|
== USAGE
|
29
30
|
|
30
31
|
You can parse strings containing a natural language interval using the Tickle.parse method.
|
31
32
|
|
32
|
-
Tickle.parse returns
|
33
|
+
Tickle.parse returns the next occurrence of the event.
|
34
|
+
|
35
|
+
You can either pass a string prefixed with the word "every, each or 'on the'" or simply the time frame. You can also pass a start date with the word "starting" (e.g. Tickle.parse('every 3 days starting next friday'))
|
33
36
|
|
34
|
-
|
37
|
+
Tickle returns nil if it cannot parse the string cannot be parsed.
|
35
38
|
|
36
39
|
Tickle HEAVILY uses chronic for parsing both the event and the start date.
|
37
40
|
|
@@ -40,110 +43,55 @@ Tickle HEAVILY uses chronic for parsing both the event and the start date.
|
|
40
43
|
require 'rubygems'
|
41
44
|
require 'tickle'
|
42
45
|
|
43
|
-
Time.now
|
44
|
-
2010-04-22
|
45
|
-
|
46
|
-
Tickle.parse('each day')
|
47
|
-
#=>
|
48
|
-
|
49
|
-
Tickle.parse('every
|
50
|
-
#=>
|
51
|
-
|
52
|
-
Tickle.parse('
|
53
|
-
#=>
|
54
|
-
|
55
|
-
Tickle.parse('every
|
56
|
-
|
57
|
-
|
58
|
-
Tickle.parse('every
|
59
|
-
|
60
|
-
|
61
|
-
Tickle.parse('
|
62
|
-
#=>
|
63
|
-
|
64
|
-
Tickle.parse('
|
65
|
-
#=>
|
66
|
-
|
67
|
-
Tickle.parse('
|
68
|
-
#=>
|
69
|
-
|
70
|
-
Tickle.parse('
|
71
|
-
|
72
|
-
|
73
|
-
Tickle.parse('
|
74
|
-
|
75
|
-
|
76
|
-
Tickle.parse('
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
Tickle.parse('every other month')
|
92
|
-
#=> [2010-04-22 16:38:12 -0400, 2010-06-22 16:38:12 -0400, 60]
|
93
|
-
|
94
|
-
Tickle.parse('every other year')
|
95
|
-
#=> [2010-04-22 16:38:12 -0400, 2012-04-22 16:38:12 -0400, 730]
|
96
|
-
|
97
|
-
Tickle.parse('every other day starting May 1st')
|
98
|
-
#=> [2010-05-01 12:00:00 -0400, 2012-04-22 16:38:12 -0400, 2]
|
99
|
-
|
100
|
-
Tickle.parse('every other week starting this Sunday')
|
101
|
-
#=> [2010-04-25 12:00:00 -0400, 2012-04-22 16:38:12 -0400, 14]
|
102
|
-
|
103
|
-
Tickle.parse('every Monday')
|
104
|
-
#=> [2010-04-26 12:00:00 -0400, 2012-04-22 16:38:12 -0400, 7]
|
105
|
-
|
106
|
-
Tickle.parse('every Wednesday')
|
107
|
-
#=> [2010-04-28 12:00:00 -0400, 2012-04-22 16:38:12 -0400, 7]
|
108
|
-
|
109
|
-
Tickle.parse('every Friday')
|
110
|
-
#=> [2010-04-23 12:00:00 -0400, 2012-04-22 16:38:12 -0400, 7]
|
111
|
-
|
112
|
-
Tickle.parse('every May')
|
113
|
-
#=> [2010-05-01 12:00:00 -0400, 2012-04-22 16:38:12 -0400, 30]
|
114
|
-
|
115
|
-
Tickle.parse('every june')
|
116
|
-
#=> [2010-06-01 12:00:00 -0400, 2012-04-22 16:38:12 -0400, 30]
|
117
|
-
|
118
|
-
Tickle.parse('beginning of the week')
|
119
|
-
#=> [2010-04-25 12:00:00 -0400, 2012-04-22 16:38:12 -0400, 7]
|
120
|
-
|
121
|
-
Tickle.parse('middle of the week')
|
122
|
-
#=> [2010-04-28 12:00:00 -0400, 2012-04-22 16:38:12 -0400, 7]
|
123
|
-
|
124
|
-
Tickle.parse('end of the week')
|
125
|
-
#=> [2010-04-24 12:00:00 -0400, 2012-04-22 16:38:12 -0400, 7]
|
126
|
-
|
127
|
-
Tickle.parse('beginning of the month')
|
128
|
-
#=> [2010-05-01 12:00:00 -0400, 2012-04-22 16:38:12 -0400, 30]
|
129
|
-
|
130
|
-
Tickle.parse('middle of the month')
|
131
|
-
#=> [2010-05-15 12:00:00 -0400, 2012-04-22 16:38:12 -0400, 30]
|
132
|
-
|
133
|
-
Tickle.parse('end of the month')
|
134
|
-
#=> [2010-04-30 00:00:00 -0400, 2012-04-22 16:38:12 -0400, 30]
|
135
|
-
|
136
|
-
Tickle.parse('beginning of the year')
|
137
|
-
#=> [2011-01-01 12:00:00 -0500, 2012-04-22 16:38:12 -0400, 365]
|
138
|
-
|
139
|
-
Tickle.parse('middle of the year')
|
140
|
-
#=> [2010-06-15 00:00:00 -0400, 2012-04-22 16:38:12 -0400, 365]
|
46
|
+
.Time.now
|
47
|
+
2010-04-22 17:11:52 -0400
|
48
|
+
|
49
|
+
Tickle.parse('each day') #=> 2010-04-23 17:24:24 -0400
|
50
|
+
Tickle.parse('every day') #=> 2010-04-23 17:24:24 -0400
|
51
|
+
Tickle.parse('every week') #=> 2010-04-29 17:24:24 -0400
|
52
|
+
Tickle.parse('every Month') #=> 2010-05-22 17:24:24 -0400
|
53
|
+
Tickle.parse('every year') #=> 2011-04-22 17:24:24 -0400
|
54
|
+
Tickle.parse('daily') #=> 2010-04-23 17:24:24 -0400
|
55
|
+
Tickle.parse('weekly') #=> 2010-04-29 17:24:24 -0400
|
56
|
+
Tickle.parse('monthly') #=> 2010-05-22 17:24:24 -0400
|
57
|
+
Tickle.parse('yearly') #=> 2011-04-22 17:24:24 -0400
|
58
|
+
Tickle.parse('every 3 days') #=> 2010-04-25 17:24:24 -0400
|
59
|
+
Tickle.parse('every 3 weeks') #=> 2010-05-13 17:24:24 -0400
|
60
|
+
Tickle.parse('every 3 months') #=> 2010-07-21 17:24:24 -0400
|
61
|
+
Tickle.parse('every 3 years') #=> 2013-04-21 17:24:24 -0400
|
62
|
+
Tickle.parse('every other day') #=> 2010-04-24 17:24:24 -0400
|
63
|
+
Tickle.parse('every other week') #=> 2010-05-06 17:24:24 -0400
|
64
|
+
Tickle.parse('every other month') #=> 2010-06-22 17:24:24 -0400
|
65
|
+
Tickle.parse('every other year') #=> 2012-04-22 17:24:24 -0400
|
66
|
+
Tickle.parse('every other day starting May 1st') #=> 2010-05-01 12:00:00 -0400
|
67
|
+
Tickle.parse('every other week starting this Sunday') #=> 2010-04-25 12:00:00 -0400
|
68
|
+
Tickle.parse('every Monday') #=> 2010-04-26 12:00:00 -0400
|
69
|
+
Tickle.parse('every Wednesday') #=> 2010-04-28 12:00:00 -0400
|
70
|
+
Tickle.parse('every Friday') #=> 2010-04-23 12:00:00 -0400
|
71
|
+
Tickle.parse('every May') #=> 2010-05-01 12:00:00 -0400
|
72
|
+
Tickle.parse('every june') #=> 2010-06-01 12:00:00 -0400
|
73
|
+
Tickle.parse('beginning of the week') #=> 2010-04-25 12:00:00 -0400
|
74
|
+
Tickle.parse('middle of the week') #=> 2010-04-28 12:00:00 -0400
|
75
|
+
Tickle.parse('end of the week') #=> 2010-04-24 12:00:00 -0400
|
76
|
+
Tickle.parse('beginning of the month') #=> 2010-05-01 12:00:00 -0400
|
77
|
+
Tickle.parse('middle of the month') #=> 2010-05-15 12:00:00 -0400
|
78
|
+
Tickle.parse('end of the month') #=> 2010-04-30 00:00:00 -0400
|
79
|
+
Tickle.parse('beginning of the year') #=> 2011-01-01 12:00:00 -0500
|
80
|
+
Tickle.parse('middle of the year') #=> 2010-06-15 00:00:00 -0400
|
81
|
+
Tickle.parse('end of the year') #=> 2010-12-31 00:00:00 -0500
|
82
|
+
|
83
|
+
|
84
|
+
-- USING IN APP
|
85
|
+
|
86
|
+
To use in your app, we recommend adding two attributes to your database model:
|
87
|
+
* next_occurrence
|
88
|
+
* tickle_query
|
89
|
+
|
90
|
+
Then call Tickle.parse(query) when you need to and save the results accordingly. In your
|
91
|
+
code, each day, simply check to see if today is >= next_occurrence and, if so, run your block.
|
92
|
+
|
93
|
+
After it completes, call Tickle.parse(tickle_query) again to update the next occurrence of the event.
|
141
94
|
|
142
|
-
Tickle.parse('end of the year')
|
143
|
-
#=> [2010-12-31 00:00:00 -0500, 2012-04-22 16:38:12 -0400, 365]
|
144
|
-
|
145
|
-
|
146
|
-
You can either pass a string prefixed with the word "every, each or 'on the'" or simply the time frame.
|
147
95
|
|
148
96
|
-- LIMITATIONS
|
149
97
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/lib/tickle/handler.rb
CHANGED
@@ -11,7 +11,12 @@ module Tickle
|
|
11
11
|
|
12
12
|
# defines the next occurrence of this tickle if not set in a guess routine
|
13
13
|
@next ||= @start + (interval * 60 * 60 * 24) if interval
|
14
|
-
|
14
|
+
|
15
|
+
# check to see if the start date is > NOW and, if so, set the next occurrence = start
|
16
|
+
@next = @start if @start.to_time > Time.now
|
17
|
+
|
18
|
+
# return the next occurrence
|
19
|
+
return @next.to_time if interval
|
15
20
|
end
|
16
21
|
|
17
22
|
def guess_unit_types
|
data/lib/tickle/tickle.rb
CHANGED
data/lib/tickle.rb
CHANGED
data/test/test_parsing.rb
CHANGED
@@ -68,9 +68,8 @@ class TestParsing < Test::Unit::TestCase
|
|
68
68
|
|
69
69
|
private
|
70
70
|
def parse_now(string, options={})
|
71
|
-
puts ("attempting to parse '#{string}'")
|
72
71
|
out = Tickle.parse(string, {}.merge(options))
|
73
|
-
|
72
|
+
puts ("Tickle.parse('#{string}') #=> #{out}")
|
74
73
|
out
|
75
74
|
end
|
76
75
|
end
|
data/tickle.gemspec
CHANGED