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 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 two variables, the next interval followed by the interval length in days. Tickle returns nil if it cannot parse the string cannot be parsed.
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 an array of first occurrence, next occurrence, interval between occurrences.
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
- You can also pass a start date with the word "starting" (e.g. Tickle.parse('every 3 days starting next friday'))
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 16:38:12 -0400
45
-
46
- Tickle.parse('each day')
47
- #=> [2010-04-22 16:38:12 -0400, 2010-04-23 16:38:12 -0400, 1]
48
-
49
- Tickle.parse('every day')
50
- #=> [2010-04-22 16:38:12 -0400, 2010-04-23 16:38:12 -0400, 1]
51
-
52
- Tickle.parse('every week')
53
- #=> [2010-04-22 16:38:12 -0400, 2010-04-23 16:38:12 -0400, 7]
54
-
55
- Tickle.parse('every Month')
56
- #=> [2010-04-22 16:38:12 -0400, 2010-04-23 16:38:12 -0400, 30]
57
-
58
- Tickle.parse('every year')
59
- #=> [2010-04-22 16:38:12 -0400, 2010-04-23 16:38:12 -0400, 365]
60
-
61
- Tickle.parse('daily')
62
- #=> [2010-04-22 16:38:12 -0400, 2010-04-23 16:38:12 -0400, 1]
63
-
64
- Tickle.parse('weekly')
65
- #=> [2010-04-22 16:38:12 -0400, 2010-04-23 16:38:12 -0400, 7]
66
-
67
- Tickle.parse('monthly')
68
- #=> [2010-04-22 16:38:12 -0400, 2010-04-23 16:38:12 -0400, 30]
69
-
70
- Tickle.parse('yearly')
71
- #=> [2010-04-22 16:38:12 -0400, 2010-04-23 16:38:12 -0400, 365]
72
-
73
- Tickle.parse('every 3 days')
74
- #=> [2010-04-22 16:38:12 -0400, 2010-04-23 16:38:12 -0400, 3]
75
-
76
- Tickle.parse('every 3 weeks')
77
- #=> [2010-04-22 16:38:12 -0400, 2010-04-23 16:38:12 -0400, 21]
78
-
79
- Tickle.parse('every 3 months')
80
- #=> [2010-04-22 16:38:12 -0400, 2010-04-23 16:38:12 -0400, 90]
81
-
82
- Tickle.parse('every 3 years')
83
- #=> [2010-04-22 16:38:12 -0400, 2010-04-23 16:38:12 -0400, 1095]
84
-
85
- Tickle.parse('every other day')
86
- #=> [2010-04-22 16:38:12 -0400, 2010-04-23 16:38:12 -0400, 2]
87
-
88
- Tickle.parse('every other week')
89
- #=> [2010-04-22 16:38:12 -0400, 2010-04-23 16:38:12 -0400, 14]
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.2
1
+ 0.0.3
@@ -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
- return [@start.to_time, @next.to_time, interval] if interval
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
@@ -23,6 +23,7 @@ module Tickle
23
23
  # check to see if this event starts some other time and reset now
24
24
  event, starting = text.split('starting')
25
25
  @start = (Chronic.parse(starting) || options[:start])
26
+ @next = nil
26
27
 
27
28
  # split into tokens
28
29
  @tokens = base_tokenize(event)
data/lib/tickle.rb CHANGED
@@ -17,7 +17,7 @@ require 'tickle/handler'
17
17
  require 'tickle/repeater'
18
18
 
19
19
  module Tickle
20
- VERSION = "0.0.2"
20
+ VERSION = "0.0.3"
21
21
 
22
22
  def self.debug; false; end
23
23
 
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
- p ("output: #{out}")
72
+ puts ("Tickle.parse('#{string}') #=> #{out}")
74
73
  out
75
74
  end
76
75
  end
data/tickle.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{tickle}
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Joshua Lippiner"]
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 2
9
- version: 0.0.2
8
+ - 3
9
+ version: 0.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Joshua Lippiner