chronic 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/chronic.rb +19 -6
- data/lib/chronic/chronic.rb +1 -1
- data/lib/chronic/handlers.rb +7 -9
- data/lib/chronic/repeaters/repeater_day_name.rb +1 -1
- data/test/test_parsing.rb +6 -0
- metadata +3 -3
data/lib/chronic.rb
CHANGED
@@ -11,17 +11,30 @@ require 'date'
|
|
11
11
|
|
12
12
|
require 'chronic/chronic'
|
13
13
|
require 'chronic/handlers'
|
14
|
+
|
15
|
+
require 'chronic/repeater'
|
16
|
+
require 'chronic/repeaters/repeater_year'
|
17
|
+
require 'chronic/repeaters/repeater_season'
|
18
|
+
require 'chronic/repeaters/repeater_season_name'
|
19
|
+
require 'chronic/repeaters/repeater_month'
|
20
|
+
require 'chronic/repeaters/repeater_month_name'
|
21
|
+
require 'chronic/repeaters/repeater_fortnight'
|
22
|
+
require 'chronic/repeaters/repeater_week'
|
23
|
+
require 'chronic/repeaters/repeater_weekend'
|
24
|
+
require 'chronic/repeaters/repeater_day'
|
25
|
+
require 'chronic/repeaters/repeater_day_name'
|
26
|
+
require 'chronic/repeaters/repeater_day_portion'
|
27
|
+
require 'chronic/repeaters/repeater_hour'
|
28
|
+
require 'chronic/repeaters/repeater_minute'
|
29
|
+
require 'chronic/repeaters/repeater_second'
|
30
|
+
require 'chronic/repeaters/repeater_time'
|
31
|
+
|
14
32
|
require 'chronic/grabber'
|
15
|
-
require 'chronic/ordinal'
|
16
33
|
require 'chronic/pointer'
|
17
34
|
require 'chronic/scalar'
|
35
|
+
require 'chronic/ordinal'
|
18
36
|
require 'chronic/separator'
|
19
37
|
|
20
|
-
require 'chronic/repeater'
|
21
|
-
Dir["#{File.dirname(__FILE__)}/chronic/repeaters/*.rb"].each do |file|
|
22
|
-
require file
|
23
|
-
end
|
24
|
-
|
25
38
|
module Chronic
|
26
39
|
def self.debug=(val); @debug = val; end
|
27
40
|
end
|
data/lib/chronic/chronic.rb
CHANGED
@@ -100,7 +100,7 @@ module Chronic
|
|
100
100
|
# to numbers (three => 3), and converting ordinal words to numeric
|
101
101
|
# ordinals (third => 3rd)
|
102
102
|
def pre_normalize(text) #:nodoc:
|
103
|
-
normalized_text = text.downcase
|
103
|
+
normalized_text = text.to_s.downcase
|
104
104
|
normalized_text.gsub!(/['"\.]/, '')
|
105
105
|
normalized_text.gsub!(/([\/\-\,\@])/) { ' ' + $1 + ' ' }
|
106
106
|
normalized_text.gsub!(/\btoday\b/, 'this day')
|
data/lib/chronic/handlers.rb
CHANGED
@@ -274,15 +274,15 @@ module Chronic
|
|
274
274
|
|
275
275
|
repeaters = self.get_repeaters(tokens)
|
276
276
|
repeaters.size.times { tokens.pop }
|
277
|
-
|
278
|
-
if tokens.
|
279
|
-
grabber = tokens.
|
277
|
+
|
278
|
+
if tokens.first && tokens.first.get_tag(Grabber)
|
279
|
+
grabber = tokens.first.get_tag(Grabber)
|
280
280
|
tokens.pop
|
281
281
|
end
|
282
282
|
|
283
283
|
head = repeaters.shift
|
284
284
|
head.start = @now
|
285
|
-
|
285
|
+
|
286
286
|
case grabber.type
|
287
287
|
when :last: outer_span = head.next(:past)
|
288
288
|
when :this: outer_span = head.this(options[:context])
|
@@ -295,11 +295,9 @@ module Chronic
|
|
295
295
|
|
296
296
|
def get_repeaters(tokens) #:nodoc:
|
297
297
|
repeaters = []
|
298
|
-
tokens.
|
298
|
+
tokens.each do |token|
|
299
299
|
if t = token.get_tag(Repeater)
|
300
300
|
repeaters << t
|
301
|
-
else
|
302
|
-
break
|
303
301
|
end
|
304
302
|
end
|
305
303
|
repeaters.sort.reverse
|
@@ -313,8 +311,8 @@ module Chronic
|
|
313
311
|
|
314
312
|
head, *rest = tags
|
315
313
|
head.start = pointer == :future ? span.begin : span.end
|
316
|
-
h = head.
|
317
|
-
|
314
|
+
h = head.this(pointer)
|
315
|
+
|
318
316
|
if span.include?(h.begin) || span.include?(h.end)
|
319
317
|
return find_within(rest, h, pointer)
|
320
318
|
else
|
data/test/test_parsing.rb
CHANGED
@@ -321,6 +321,12 @@ class TestParsing < Test::Unit::TestCase
|
|
321
321
|
end
|
322
322
|
|
323
323
|
def test_parse_guess_grrr
|
324
|
+
time = Chronic.parse("today at 6:00pm", :now => @time_2006_08_16_14_00_00)
|
325
|
+
assert_equal Time.local(2006, 8, 16, 18), time
|
326
|
+
|
327
|
+
time = Chronic.parse("this day 1800", :now => @time_2006_08_16_14_00_00)
|
328
|
+
assert_equal Time.local(2006, 8, 16, 18), time
|
329
|
+
|
324
330
|
time = Chronic.parse("yesterday at 4:00pm", :now => @time_2006_08_16_14_00_00)
|
325
331
|
assert_equal Time.local(2006, 8, 15, 16), time
|
326
332
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: chronic
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.1.
|
7
|
-
date: 2006-09-
|
6
|
+
version: 0.1.1
|
7
|
+
date: 2006-09-09 00:00:00 -07:00
|
8
8
|
summary: A natural language date parser
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -26,7 +26,7 @@ platform: ruby
|
|
26
26
|
signing_key:
|
27
27
|
cert_chain:
|
28
28
|
authors:
|
29
|
-
- Tom Werner
|
29
|
+
- Tom Preston-Werner
|
30
30
|
files:
|
31
31
|
- lib/chronic
|
32
32
|
- lib/chronic.rb
|