tickle 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +6 -2
- data/VERSION +1 -1
- data/git-flow-version +1 -1
- data/lib/tickle.rb +1 -1
- data/lib/tickle/handler.rb +0 -1
- data/lib/tickle/repeater.rb +3 -4
- data/lib/tickle/tickle.rb +24 -4
- data/test/test_parsing.rb +59 -51
- data/tickle.gemspec +2 -2
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -88,8 +88,12 @@ Tickle HEAVILY uses chronic for parsing both the event and the start date.
|
|
88
88
|
Tickle.parse('the fifth') #=> 2010-05-05 12:00:00 -0400
|
89
89
|
Tickle.parse('the 3rd Sunday of May') #=> 2010-05-16 12:00:00 -0400
|
90
90
|
Tickle.parse('the 3rd Sunday of the month') #=> 2010-05-16 12:00:00 -0400
|
91
|
-
|
92
|
-
|
91
|
+
Tickle.parse('the 23rd of June') #=> 2010-06-23 12:00:00 -0400
|
92
|
+
Tickle.parse('the twenty third of June') #=> 2010-06-23 12:00:00 -0400
|
93
|
+
Tickle.parse('the thirty first of August') #=> 2010-08-31 12:00:00 -0400
|
94
|
+
Tickle.parse('the twenty first') #=> 2010-05-21 12:00:00 -0400
|
95
|
+
Tickle.parse('the twenty first of the month') #=> 2010-05-21 12:00:00 -0400
|
96
|
+
|
93
97
|
|
94
98
|
-- USING IN APP
|
95
99
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.5
|
data/git-flow-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
GITFLOW_VERSION=0.0.
|
1
|
+
GITFLOW_VERSION=0.0.5
|
data/lib/tickle.rb
CHANGED
@@ -45,7 +45,7 @@ end
|
|
45
45
|
|
46
46
|
class String
|
47
47
|
def is_ordinal?
|
48
|
-
scanner = %w{first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth thirteenth fourteenth fifteenth sixteenth
|
48
|
+
scanner = %w{first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth thirteenth fourteenth fifteenth sixteenth seventeenth eighteenth nineteenth twenty thirty thirtieth}
|
49
49
|
regex = /\b(\d*)(st|nd|rd|th)\b/
|
50
50
|
!(self =~ regex).nil? || scanner.include?(self.downcase)
|
51
51
|
end
|
data/lib/tickle/handler.rb
CHANGED
data/lib/tickle/repeater.rb
CHANGED
@@ -16,7 +16,7 @@ class Tickle::Repeater < Chronic::Tag #:nodoc:
|
|
16
16
|
|
17
17
|
def self.scan_for_numbers(token)
|
18
18
|
num = Float(token.word) rescue nil
|
19
|
-
token.update(:number,
|
19
|
+
token.update(:number, num.to_i, num.to_i) if num
|
20
20
|
token
|
21
21
|
end
|
22
22
|
|
@@ -40,8 +40,7 @@ class Tickle::Repeater < Chronic::Tag #:nodoc:
|
|
40
40
|
/seventeenth/ => '17th',
|
41
41
|
/eighteenth/ => '18th',
|
42
42
|
/nineteenth/ => '19th',
|
43
|
-
/
|
44
|
-
/thirty/ => '30th',
|
43
|
+
/twentieth/ => '20th',
|
45
44
|
/thirtieth/ => '30th',
|
46
45
|
}
|
47
46
|
scanner.keys.each do |scanner_item|
|
@@ -55,7 +54,7 @@ class Tickle::Repeater < Chronic::Tag #:nodoc:
|
|
55
54
|
token.update(:ordinal, token.original, 365) if !(token.original =~ regex).nil?
|
56
55
|
token
|
57
56
|
end
|
58
|
-
|
57
|
+
|
59
58
|
def self.scan_for_month_names(token)
|
60
59
|
scanner = {/^jan\.?(uary)?$/ => :january,
|
61
60
|
/^feb\.?(ruary)?$/ => :february,
|
data/lib/tickle/tickle.rb
CHANGED
@@ -32,6 +32,11 @@ module Tickle
|
|
32
32
|
# remove all tokens without a type
|
33
33
|
@tokens.reject! {|token| token.type.nil? }
|
34
34
|
|
35
|
+
# combine number and ordinals into single number
|
36
|
+
combine_multiple_numbers
|
37
|
+
|
38
|
+
@tokens.each {|x| puts x.inspect} if Tickle.debug
|
39
|
+
|
35
40
|
return guess
|
36
41
|
end
|
37
42
|
|
@@ -55,7 +60,7 @@ module Tickle
|
|
55
60
|
token.word = normalize(token.original)
|
56
61
|
end
|
57
62
|
end
|
58
|
-
|
63
|
+
|
59
64
|
# Clean up the specified input text by stripping unwanted characters,
|
60
65
|
# converting idioms to their canonical form, converting number words
|
61
66
|
# to numbers (three => 3), and converting ordinal words to numeric
|
@@ -87,7 +92,19 @@ module Tickle
|
|
87
92
|
def numericize_ordinals(text) #:nodoc:
|
88
93
|
text = text.gsub(/\b(\d*)(st|nd|rd|th)\b/, '\1')
|
89
94
|
end
|
90
|
-
|
95
|
+
|
96
|
+
# Turns compound numbers, like 'twenty first' => 21
|
97
|
+
def combine_multiple_numbers
|
98
|
+
if [:number, :ordinal].all? {|type| token_types.include? type}
|
99
|
+
number = token_of_type(:number)
|
100
|
+
ordinal = token_of_type(:ordinal)
|
101
|
+
combined_value = (number.start.to_s[0] + ordinal.start.to_s)
|
102
|
+
new_number_token = Token.new(combined_value, combined_value, :ordinal, combined_value, 365)
|
103
|
+
@tokens.reject! {|token| (token.type == :number || token.type == :ordinal)}
|
104
|
+
@tokens << new_number_token
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
91
108
|
# Returns an array of types for all tokens
|
92
109
|
def token_types
|
93
110
|
@tokens.map(&:type)
|
@@ -97,9 +114,12 @@ module Tickle
|
|
97
114
|
class Token #:nodoc:
|
98
115
|
attr_accessor :original, :word, :type, :interval, :start
|
99
116
|
|
100
|
-
def initialize(original)
|
117
|
+
def initialize(original, word=nil, type=nil, start=nil, interval=nil)
|
101
118
|
@original = original
|
102
|
-
@word =
|
119
|
+
@word = word
|
120
|
+
@type = type
|
121
|
+
@interval = interval
|
122
|
+
@start = start
|
103
123
|
end
|
104
124
|
|
105
125
|
def update(type, start=nil, interval=nil)
|
data/test/test_parsing.rb
CHANGED
@@ -13,60 +13,68 @@ class TestParsing < Test::Unit::TestCase
|
|
13
13
|
p Time.now
|
14
14
|
|
15
15
|
parse_now('each day')
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
16
|
+
|
17
|
+
parse_now('every day')
|
18
|
+
parse_now('every week')
|
19
|
+
parse_now('every Month')
|
20
|
+
parse_now('every year')
|
21
|
+
|
22
|
+
parse_now('daily')
|
23
|
+
parse_now('weekly')
|
24
|
+
parse_now('monthly')
|
25
|
+
parse_now('yearly')
|
26
|
+
|
27
|
+
parse_now('every 3 days')
|
28
|
+
parse_now('every 3 weeks')
|
29
|
+
parse_now('every 3 months')
|
30
|
+
parse_now('every 3 years')
|
31
|
+
|
32
|
+
parse_now('every other day')
|
33
|
+
parse_now('every other week')
|
34
|
+
parse_now('every other month')
|
35
|
+
parse_now('every other year')
|
36
|
+
parse_now('every other day starting May 1st')
|
37
|
+
parse_now('every other week starting this Sunday')
|
38
|
+
|
39
|
+
parse_now('every Monday')
|
40
|
+
parse_now('every Wednesday')
|
41
|
+
parse_now('every Friday')
|
42
|
+
|
43
|
+
parse_now('every May')
|
44
|
+
parse_now('every june')
|
45
|
+
|
46
|
+
parse_now('beginning of the week')
|
47
|
+
parse_now('middle of the week')
|
48
|
+
parse_now('end of the week')
|
49
|
+
|
50
|
+
parse_now('beginning of the month')
|
51
|
+
parse_now('middle of the month')
|
52
|
+
parse_now('end of the month')
|
53
|
+
|
54
|
+
parse_now('beginning of the year')
|
55
|
+
parse_now('middle of the year')
|
56
|
+
parse_now('end of the year')
|
57
|
+
|
58
|
+
parse_now('the 3rd of May')
|
59
|
+
parse_now('the 3rd of February', {:start => Date.new(2010, 03, 01).to_time})
|
60
|
+
|
61
|
+
parse_now('the 10th of the month')
|
62
|
+
parse_now('the tenth of the month')
|
63
|
+
|
64
|
+
parse_now('the first of the month')
|
65
|
+
parse_now('the thirtieth')
|
66
|
+
parse_now('the fifth', {:start => Date.new(2010, 03, 15)})
|
67
67
|
|
68
68
|
parse_now('the 3rd Sunday of May')
|
69
69
|
parse_now('the 3rd Sunday of the month')
|
70
|
+
|
71
|
+
parse_now('the 23rd of June')
|
72
|
+
parse_now('the twenty third of June')
|
73
|
+
parse_now('the thirty first of August')
|
74
|
+
|
75
|
+
|
76
|
+
parse_now('the twenty first')
|
77
|
+
parse_now('the twenty first of the month')
|
70
78
|
end
|
71
79
|
|
72
80
|
def test_argument_validation
|
data/tickle.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{tickle}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.5"
|
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"]
|
12
|
-
s.date = %q{2010-04-
|
12
|
+
s.date = %q{2010-04-25}
|
13
13
|
s.description = %q{Tickle is a date/time helper gem to help parse natural language into a recurring pattern. Tickle is designed to be a compliment of Chronic and can interpret things such as "every 2 days, every Sunday, Sundays, Weekly, etc.}
|
14
14
|
s.email = %q{jlippiner@noctivity.com}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 5
|
9
|
+
version: 0.0.5
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Joshua Lippiner
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-04-
|
17
|
+
date: 2010-04-25 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|