eventual 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +14 -16
- data/VERSION +1 -1
- data/lib/eventual/syntax_nodes.rb +18 -12
- data/lib/eventual.rb +28 -1
- data/spec/es_eventual_spec.rb +51 -53
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -14,59 +14,57 @@ Ejemplos:
|
|
14
14
|
require 'rubygems'
|
15
15
|
require 'eventual'
|
16
16
|
|
17
|
-
|
17
|
+
Eventual.parse( 'del 5 al 7 de junio del 2009' ).map
|
18
18
|
=> [#<DateTime: 4909975/2,0,2299161>, #<DateTime: 4909977/2,0,2299161>, #<DateTime: 4909979/2,0,2299161>]
|
19
19
|
|
20
20
|
# Si no se especifica el año se usará el año actual
|
21
|
-
|
21
|
+
Eventual.parse( 'del 5 al 7 de junio' ).map{ |d| d.to_s } # Quizá mas tarde se localize a otros idiomas
|
22
22
|
=> ["2010-06-05", "2010-06-06", "2010-06-07"]
|
23
23
|
|
24
24
|
# Se puede especificar un año por omisión
|
25
|
-
dates =
|
26
|
-
dates.year = 2007
|
25
|
+
dates = Eventual.parse( 'del 5 al 7 de junio', :default_year => 2007 )
|
27
26
|
dates.map{ |d| d.to_s }
|
28
27
|
=> ["2007-06-05", "2007-06-06", "2007-06-07"]
|
29
28
|
|
30
29
|
# Si se especifica la hora el resultado será un Array de DateTime
|
31
|
-
|
30
|
+
Eventual.parse( 'del 5 al 7 de junio del 2009 a las 16:00 y 18:00 horas', :lang => :es ).map
|
32
31
|
=> [#<DateTime: 14729929/6,0,2299161>, #<DateTime: 9819953/4,0,2299161>, #<DateTime: 14729935/6,0,2299161>, #<DateTime: 9819957/4,0,2299161>, #<DateTime: 14729941/6,0,2299161>, #<DateTime: 9819961/4,0,2299161>]
|
33
32
|
|
34
|
-
|
33
|
+
Eventual.parse( 'del 5 al 7 de junio del 2009 a las 16:00 y 18:00 horas' ).map{ |d| d.to_s }
|
35
34
|
=> ["2009-06-05T16:00:00+00:00", "2009-06-05T18:00:00+00:00", "2009-06-06T16:00:00+00:00", "2009-06-06T18:00:00+00:00", "2009-06-07T16:00:00+00:00", "2009-06-07T18:00:00+00:00"]
|
36
35
|
|
37
36
|
# Se pueden restringir los resultados a ciertos dias
|
38
|
-
|
37
|
+
Eventual.parse('lunes y martes de diciembre del 2001 a las 15:00').map{ |d| d.to_s }
|
39
38
|
=> ["2010-12-06T15:00:00+00:00", "2010-12-07T15:00:00+00:00", "2010-12-13T15:00:00+00:00", "2010-12-14T15:00:00+00:00", "2010-12-20T15:00:00+00:00", "2010-12-21T15:00:00+00:00", "2010-12-27T15:00:00+00:00", "2010-12-28T15:00:00+00:00"]
|
40
39
|
|
41
40
|
# Se puede checar si las fechas reconocidas incluyen cierta fecha, la comparación es "perezosa" es decir no instancia todos los objetos Date o DateTime
|
42
41
|
# como hace map y por lo tanto es mas eficiente
|
43
|
-
|
42
|
+
Eventual.parse( 'del 5 al 7 de junio del 2007' ).include? Date.civil(2007, 6, 6)
|
44
43
|
=> true
|
45
44
|
|
46
|
-
|
45
|
+
Eventual.parse( 'del 5 al 7 de junio del 2007' ).include? Date.civil(2006, 6, 6)
|
47
46
|
=> false
|
48
47
|
|
49
48
|
# Se toma en cuenta la hora
|
50
|
-
|
49
|
+
Eventual.parse( 'del 5 al 7 de junio del 2007 a las 16:00' ).include? DateTime.civil(2007, 6, 6, 16, 0)
|
51
50
|
=> true
|
52
51
|
|
53
|
-
|
52
|
+
Eventual.parse( 'del 5 al 7 de junio del 2007 a las 16:00' ).include? DateTime.civil(2007, 6, 6, 15, 0)
|
54
53
|
=> false
|
55
54
|
|
56
55
|
# Si se pasa un Date que corresponda al periodo la comparación es positiva
|
57
|
-
|
56
|
+
Eventual.parse( 'del 5 al 7 de junio del 2007 a las 16:00' ).include? Date.civil(2007, 6, 6)
|
58
57
|
=> true
|
59
58
|
|
60
59
|
# El evento tiene una duración por omisión de 60 minutos
|
61
|
-
|
60
|
+
Eventual.parse( 'del 5 al 7 de junio del 2007 a las 16:00' ).include? DateTime.civil(2007, 6, 6, 16, 59)
|
62
61
|
=> true
|
63
62
|
|
64
|
-
|
63
|
+
Eventual.parse( 'del 5 al 7 de junio del 2007 a las 16:00' ).include? DateTime.civil(2007, 6, 6, 17, 00)
|
65
64
|
=> false
|
66
65
|
|
67
66
|
# Pero se puede cambiar
|
68
|
-
dates =
|
69
|
-
dates.time_span = 120
|
67
|
+
dates = Eventual.parse( 'del 5 al 7 de junio del 2007 a las 16:00', :default_event_span => 120)
|
70
68
|
dates.include? DateTime.civil(2007, 6, 6, 17, 00)
|
71
69
|
=> true
|
72
70
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.2
|
@@ -4,7 +4,7 @@ module Eventual
|
|
4
4
|
ShortMonthNames = %w(ene feb mar abr may jun jul ago sept oct nov dic).freeze
|
5
5
|
WdaysR = [/d/, /l/, /ma/, /mi/, /j/, /v/, /s/].freeze
|
6
6
|
WdayListR = /\b(?:#{ WdaysR.join('|') })/.freeze
|
7
|
-
|
7
|
+
# :nodoc:
|
8
8
|
class WdayMatchError < StandardError
|
9
9
|
def initialize value, wday_index
|
10
10
|
@value, @wday_index = value, wday_index
|
@@ -14,7 +14,7 @@ module Eventual
|
|
14
14
|
"El #{@value.day} de #{MonthNames[@value.month]} del #{@value.year} cae en #{Weekdays[@value.wday]} no #{Weekdays[@wday_index]}"
|
15
15
|
end
|
16
16
|
end
|
17
|
-
|
17
|
+
# :nodoc:
|
18
18
|
class Year < Treetop::Runtime::SyntaxNode
|
19
19
|
def value
|
20
20
|
match = text_value.match(/(')?(\d{2,4})/)
|
@@ -23,7 +23,7 @@ module Eventual
|
|
23
23
|
value
|
24
24
|
end
|
25
25
|
end
|
26
|
-
|
26
|
+
# :nodoc:
|
27
27
|
class WeekdayConstrain < Treetop::Runtime::SyntaxNode
|
28
28
|
def value
|
29
29
|
text = wdays_node.text_value.sub('semana', '')
|
@@ -33,42 +33,47 @@ module Eventual
|
|
33
33
|
days.uniq
|
34
34
|
end
|
35
35
|
end
|
36
|
-
|
36
|
+
# :nodoc:
|
37
37
|
class MonthName < Treetop::Runtime::SyntaxNode
|
38
38
|
def value
|
39
39
|
ShortMonthNames.index(text_value.downcase.match(/#{ ShortMonthNames.join('|') }/).to_s) + 1
|
40
40
|
end
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
class Node < Treetop::Runtime::SyntaxNode
|
44
44
|
attr_accessor :year
|
45
45
|
attr_accessor :time_span
|
46
|
-
|
47
46
|
attr_accessor :month
|
48
47
|
attr_accessor :weekdays
|
49
48
|
attr_accessor :times
|
50
49
|
|
50
|
+
# Returns last Date or DateTime of the encompassed period
|
51
51
|
def last
|
52
52
|
to_a.last
|
53
53
|
end
|
54
54
|
|
55
|
+
# Returns last Date or DateTime of the encompassed period
|
55
56
|
def first
|
56
57
|
to_a.first
|
57
58
|
end
|
58
59
|
|
60
|
+
# Returns an array with all the encompassed Dates or DateTimes
|
59
61
|
def to_a
|
60
62
|
map
|
61
63
|
end
|
62
64
|
|
65
|
+
# Returns true if the weekday (as number) correspons to any allowed weekday
|
63
66
|
def date_within_weekdays? date
|
64
67
|
return true unless weekdays
|
65
68
|
weekdays.include?(date.wday)
|
66
69
|
end
|
67
70
|
|
71
|
+
# Invokes block once for each Date or DateTime. Creates a new array containing the values returned by the block.
|
68
72
|
def map &block
|
69
73
|
walk { |elements| elements.map &block }
|
70
74
|
end
|
71
75
|
|
76
|
+
# Returns true if the Date or DateTime passed is included in the parsed Dates or DateTimes
|
72
77
|
def include? date
|
73
78
|
result = false
|
74
79
|
walk { |elements| break result = true if elements.include? date }
|
@@ -123,6 +128,7 @@ module Eventual
|
|
123
128
|
end
|
124
129
|
end
|
125
130
|
|
131
|
+
# :nodoc:
|
126
132
|
class Day < Node
|
127
133
|
def map &block
|
128
134
|
dates = times ? times.map{ |time| DateTime.civil year, month, text_value.to_i, time.hour, time.minute } : [Date.civil(year, month, text_value.to_i)]
|
@@ -134,7 +140,7 @@ module Eventual
|
|
134
140
|
to_a.include? date
|
135
141
|
end
|
136
142
|
end
|
137
|
-
|
143
|
+
# :nodoc:
|
138
144
|
class Period < Node
|
139
145
|
def range
|
140
146
|
(first..last)
|
@@ -162,7 +168,7 @@ module Eventual
|
|
162
168
|
array
|
163
169
|
end
|
164
170
|
end
|
165
|
-
|
171
|
+
# :nodoc:
|
166
172
|
class MonthPeriod < Period
|
167
173
|
def first
|
168
174
|
return Date.civil(year, month_name.value) unless times and !times.empty?
|
@@ -177,7 +183,7 @@ module Eventual
|
|
177
183
|
DateTime.civil(date.year, date.month, date.day, time.hour, time.minute)
|
178
184
|
end
|
179
185
|
end
|
180
|
-
|
186
|
+
# :nodoc:
|
181
187
|
class DatePeriod < Period
|
182
188
|
def first
|
183
189
|
node_map.first
|
@@ -187,7 +193,7 @@ module Eventual
|
|
187
193
|
node_map.last
|
188
194
|
end
|
189
195
|
end
|
190
|
-
|
196
|
+
# :nodoc:
|
191
197
|
class Times < Treetop::Runtime::SyntaxNode
|
192
198
|
def map
|
193
199
|
walk_times = lambda do |elements|
|
@@ -197,7 +203,7 @@ module Eventual
|
|
197
203
|
walk_times.call(elements).flatten.compact.sort_by{ |t| '%02d%02d' % [t.hour, t.minute] }
|
198
204
|
end
|
199
205
|
end
|
200
|
-
|
206
|
+
# :nodoc:
|
201
207
|
class Time < Treetop::Runtime::SyntaxNode
|
202
208
|
attr_accessor :hour, :minute
|
203
209
|
def value
|
@@ -206,7 +212,7 @@ module Eventual
|
|
206
212
|
self
|
207
213
|
end
|
208
214
|
end
|
209
|
-
|
215
|
+
# :nodoc:
|
210
216
|
class Time12 < Time
|
211
217
|
def value
|
212
218
|
super
|
data/lib/eventual.rb
CHANGED
@@ -4,4 +4,31 @@ require 'date'
|
|
4
4
|
|
5
5
|
require "#{ File.dirname __FILE__ }/eventual/syntax_nodes"
|
6
6
|
|
7
|
-
autoload :EsDatesParser, 'eventual/es'
|
7
|
+
autoload :EsDatesParser, 'eventual/es'
|
8
|
+
|
9
|
+
module Eventual
|
10
|
+
# Parses dates specified in natural language and returns an Eventual::Node object
|
11
|
+
# Eventual.parse( 'del 5 al 7 de junio del 2009' ).map
|
12
|
+
# => [#<DateTime: 4909975/2,0,2299161>, #<DateTime: 4909977/2,0,2299161>, #<DateTime: 4909979/2,0,2299161
|
13
|
+
# Options:
|
14
|
+
# +:lang+:
|
15
|
+
# Defaults to 'Es', the language to be used for parsing, currently only spanish is supported, hang on.
|
16
|
+
# +:default_year+:
|
17
|
+
# The default year to be used in case year is not specified in the text, defaults to current year
|
18
|
+
# +:default_event_span+:
|
19
|
+
# The duration in minutes an event has, defaults to 60
|
20
|
+
#
|
21
|
+
def self.parse text, opts = {}
|
22
|
+
lang = opts.delete(:lang) || 'Es'
|
23
|
+
year = opts.delete(:default_year)
|
24
|
+
span = opts.delete(:default_event_span)
|
25
|
+
|
26
|
+
raise ArgumentError, "Expected option `:default_year` to be an integer" if year && !(Integer === year)
|
27
|
+
raise ArgumentError, "Expected option `:default_event_span` to be an integer" if span && !(Integer === span)
|
28
|
+
|
29
|
+
node = const_get("#{ lang.to_s[0..1].capitalize }DatesParser").new.parse(text)
|
30
|
+
node.year = year if year
|
31
|
+
node.time_span = span if span
|
32
|
+
node
|
33
|
+
end
|
34
|
+
end
|
data/spec/es_eventual_spec.rb
CHANGED
@@ -3,7 +3,6 @@ require 'eventual'
|
|
3
3
|
|
4
4
|
describe Eventual, 'Es' do
|
5
5
|
before do
|
6
|
-
@parser = EsDatesParser.new
|
7
6
|
Date.stub!(:today).and_return Date.civil(2010)
|
8
7
|
end
|
9
8
|
|
@@ -20,7 +19,7 @@ describe Eventual, 'Es' do
|
|
20
19
|
describe 'month' do
|
21
20
|
describe "month without year parsing 'marzo'" do
|
22
21
|
before do
|
23
|
-
@result =
|
22
|
+
@result = Eventual.parse 'marzo', :lang => 'Es'
|
24
23
|
@dates = (Date.parse('2010-3-1')..Date.parse('2010-3-31')).map
|
25
24
|
end
|
26
25
|
it_should_behave_like 'correctly parses'
|
@@ -29,7 +28,7 @@ describe Eventual, 'Es' do
|
|
29
28
|
describe 'month with year' do
|
30
29
|
describe "parsing 'marzo de 2009'" do
|
31
30
|
before do
|
32
|
-
@result =
|
31
|
+
@result = Eventual.parse "marzo de 2009"
|
33
32
|
@dates = (Date.parse('2009-3-1')..Date.parse('2009-3-31')).map
|
34
33
|
end
|
35
34
|
it_should_behave_like 'correctly parses'
|
@@ -37,7 +36,7 @@ describe Eventual, 'Es' do
|
|
37
36
|
|
38
37
|
describe "parsing 'marzo del 2009'" do
|
39
38
|
before do
|
40
|
-
@result =
|
39
|
+
@result = Eventual.parse "marzo del 2009"
|
41
40
|
@dates = (Date.parse('2009-3-1')..Date.parse('2009-3-31')).map
|
42
41
|
end
|
43
42
|
it_should_behave_like 'correctly parses'
|
@@ -45,7 +44,7 @@ describe Eventual, 'Es' do
|
|
45
44
|
|
46
45
|
describe "parsing 'marzo 2009'" do
|
47
46
|
before do
|
48
|
-
@result =
|
47
|
+
@result = Eventual.parse "marzo 2009"
|
49
48
|
@dates = (Date.parse('2009-3-1')..Date.parse('2009-3-31')).map
|
50
49
|
end
|
51
50
|
it_should_behave_like 'correctly parses'
|
@@ -53,7 +52,7 @@ describe Eventual, 'Es' do
|
|
53
52
|
|
54
53
|
describe "parsing 'marzo, 2009'" do
|
55
54
|
before do
|
56
|
-
@result =
|
55
|
+
@result = Eventual.parse "marzo, 2009"
|
57
56
|
@dates = (Date.parse('2009-3-1')..Date.parse('2009-3-31')).map
|
58
57
|
end
|
59
58
|
it_should_behave_like 'correctly parses'
|
@@ -61,7 +60,7 @@ describe Eventual, 'Es' do
|
|
61
60
|
|
62
61
|
describe "parsing 'marzo '09'" do
|
63
62
|
before do
|
64
|
-
@result =
|
63
|
+
@result = Eventual.parse "marzo '09"
|
65
64
|
@dates = (Date.parse('2009-3-1')..Date.parse('2009-3-31')).map
|
66
65
|
end
|
67
66
|
it_should_behave_like 'correctly parses'
|
@@ -74,27 +73,27 @@ describe Eventual, 'Es' do
|
|
74
73
|
end
|
75
74
|
|
76
75
|
describe "parsing 'lunes y martes marzo del 2010'" do
|
77
|
-
before { @result =
|
76
|
+
before { @result = Eventual.parse "lunes y martes marzo del 2010" }
|
78
77
|
it_should_behave_like 'correctly parses'
|
79
78
|
end
|
80
79
|
|
81
80
|
describe "parsing 'lunes y martes de marzo del 2010'" do
|
82
|
-
before { @result =
|
81
|
+
before { @result = Eventual.parse "lunes y martes de marzo del 2010" }
|
83
82
|
it_should_behave_like 'correctly parses'
|
84
83
|
end
|
85
84
|
|
86
85
|
describe "parsing 'lunes y martes durante marzo del 2010'" do
|
87
|
-
before { @result =
|
86
|
+
before { @result = Eventual.parse "lunes y martes durante marzo del 2010" }
|
88
87
|
it_should_behave_like 'correctly parses'
|
89
88
|
end
|
90
89
|
|
91
90
|
describe "parsing 'lunes y martes durante todo marzo del 2010'" do
|
92
|
-
before { @result =
|
91
|
+
before { @result = Eventual.parse "lunes y martes durante todo marzo del 2010" }
|
93
92
|
it_should_behave_like 'correctly parses'
|
94
93
|
end
|
95
94
|
|
96
95
|
describe "parsing 'lunes y martes, marzo del 2010'" do
|
97
|
-
before { @result =
|
96
|
+
before { @result = Eventual.parse "lunes y martes, marzo del 2010" }
|
98
97
|
it_should_behave_like 'correctly parses'
|
99
98
|
end
|
100
99
|
end
|
@@ -108,28 +107,28 @@ describe Eventual, 'Es' do
|
|
108
107
|
end
|
109
108
|
|
110
109
|
describe "should single day number for '21 de marzo'" do
|
111
|
-
before { @result =
|
110
|
+
before { @result = Eventual.parse("21 de marzo") }
|
112
111
|
it_should_behave_like 'correctly parses'
|
113
112
|
end
|
114
113
|
|
115
114
|
describe "parsing '21 marzo'" do
|
116
|
-
before { @result =
|
115
|
+
before { @result = Eventual.parse("21 marzo") }
|
117
116
|
it_should_behave_like 'correctly parses'
|
118
117
|
end
|
119
118
|
|
120
119
|
# describe "parsing 'marzo 21'" do
|
121
|
-
# before { @result =
|
120
|
+
# before { @result = Eventual.parse("21 marzo") }
|
122
121
|
# it_should_behave_like 'correctly parses'
|
123
122
|
# end
|
124
123
|
|
125
124
|
describe 'date with wday' do
|
126
125
|
describe "parsing 'domingo 21 de marzo'" do
|
127
|
-
before { @result =
|
126
|
+
before { @result = Eventual.parse("domingo 21 de marzo") }
|
128
127
|
it_should_behave_like 'correctly parses'
|
129
128
|
end
|
130
129
|
|
131
130
|
it "should raise WdayMatchError if weekday doesn't correspond to date" do
|
132
|
-
lambda {
|
131
|
+
lambda { Eventual.parse("lunes 21 de marzo").map }.should raise_error(Eventual::WdayMatchError)
|
133
132
|
end
|
134
133
|
end
|
135
134
|
end
|
@@ -140,22 +139,22 @@ describe Eventual, 'Es' do
|
|
140
139
|
end
|
141
140
|
|
142
141
|
describe "day list for '1, 2 y 3 de marzo'" do
|
143
|
-
before { @result =
|
142
|
+
before { @result = Eventual.parse("1, 2 y 3 marzo") }
|
144
143
|
it_should_behave_like 'correctly parses'
|
145
144
|
end
|
146
145
|
|
147
146
|
describe "day list for '1, 2 y 3 marzo'" do
|
148
|
-
before { @result =
|
147
|
+
before { @result = Eventual.parse("1, 2 y 3 de marzo") }
|
149
148
|
it_should_behave_like 'correctly parses'
|
150
149
|
end
|
151
150
|
|
152
151
|
describe "day list with weekday 'lunes 1, martes 2 y miercoles 3 de marzo'" do
|
153
|
-
before { @result =
|
152
|
+
before { @result = Eventual.parse("lunes 1, martes 2 y miercoles 3 de marzo") }
|
154
153
|
it_should_behave_like 'correctly parses'
|
155
154
|
end
|
156
155
|
|
157
156
|
it "should raise WdayMatchError if weekday doesn't correspond to date" do
|
158
|
-
lambda {
|
157
|
+
lambda { Eventual.parse("lunes 2, martes 2 y jueves 3 de marzo").map }.should raise_error(Eventual::WdayMatchError)
|
159
158
|
end
|
160
159
|
end
|
161
160
|
end
|
@@ -167,29 +166,29 @@ describe Eventual, 'Es' do
|
|
167
166
|
end
|
168
167
|
|
169
168
|
describe "day list for '1 al 3 de marzo" do
|
170
|
-
before { @result =
|
169
|
+
before { @result = Eventual.parse("1 al 3 de marzo del '10") }
|
171
170
|
it_should_behave_like 'correctly parses'
|
172
171
|
end
|
173
172
|
|
174
173
|
describe "day list for '1 al 3, marzo" do
|
175
|
-
before { @result =
|
174
|
+
before { @result = Eventual.parse("1 al 3, marzo del '10") }
|
176
175
|
it_should_behave_like 'correctly parses'
|
177
176
|
end
|
178
177
|
|
179
178
|
describe "day list for 'del 1 al 3 de marzo" do
|
180
|
-
before { @result =
|
179
|
+
before { @result = Eventual.parse("del 1 al 3 de marzo del '10") }
|
181
180
|
it_should_behave_like 'correctly parses'
|
182
181
|
end
|
183
182
|
|
184
183
|
describe "day list for 'del 1 al 3, marzo" do
|
185
|
-
before { @result =
|
184
|
+
before { @result = Eventual.parse("del 1 al 3, marzo del '10") }
|
186
185
|
it_should_behave_like 'correctly parses'
|
187
186
|
end
|
188
187
|
end
|
189
188
|
|
190
189
|
describe "spanning diferent months '24 de febrero al 3 de marzo del 2010" do
|
191
190
|
before do
|
192
|
-
@result =
|
191
|
+
@result = Eventual.parse "24 de febrero al 3 de marzo del 2010"
|
193
192
|
@dates = (Date.parse('2010-2-24')..Date.parse('2010-3-3'))
|
194
193
|
end
|
195
194
|
it_should_behave_like 'correctly parses'
|
@@ -197,7 +196,7 @@ describe Eventual, 'Es' do
|
|
197
196
|
|
198
197
|
describe "spanning diferent years '24 de diciembre del 2009 al 3 de enero del 2010" do
|
199
198
|
before do
|
200
|
-
@result =
|
199
|
+
@result = Eventual.parse("24 de diciembre del 2009 al 3 de enero del 2010")
|
201
200
|
@dates = (Date.parse('2009-12-24')..Date.parse('2010-1-3'))
|
202
201
|
end
|
203
202
|
it_should_behave_like 'correctly parses'
|
@@ -209,24 +208,24 @@ describe Eventual, 'Es' do
|
|
209
208
|
end
|
210
209
|
|
211
210
|
describe "1 de octubre a 2 de diciembre del 2008" do
|
212
|
-
before { @result =
|
211
|
+
before { @result = Eventual.parse "1 de octubre a 2 de diciembre del 2008" }
|
213
212
|
it_should_behave_like 'correctly parses'
|
214
213
|
end
|
215
214
|
|
216
215
|
describe "1 de octubre al 2 de diciembre del 2008" do
|
217
|
-
before { @result =
|
216
|
+
before { @result = Eventual.parse "1 de octubre al 2 de diciembre del 2008" }
|
218
217
|
it_should_behave_like 'correctly parses'
|
219
218
|
end
|
220
219
|
|
221
220
|
describe "del miercoles 1 de octubre al martes 2 de diciembre del 2008" do
|
222
|
-
before { @result =
|
221
|
+
before { @result = Eventual.parse "del miercoles 1 de octubre al martes 2 de diciembre del 2008" }
|
223
222
|
it_should_behave_like 'correctly parses'
|
224
223
|
end
|
225
224
|
end
|
226
225
|
|
227
226
|
describe "lunes y martes del 1 de octubre al 2 de diciembre del 2008" do
|
228
227
|
before do
|
229
|
-
@result =
|
228
|
+
@result = Eventual.parse "lunes y martes del 1 de octubre al 2 de diciembre del 2008"
|
230
229
|
@dates = (Date.parse('2008-10-1')..DateTime.parse('2008-12-2')).reject{ |day| not [1,2].include?(day.wday) }
|
231
230
|
end
|
232
231
|
it_should_behave_like 'correctly parses'
|
@@ -235,7 +234,7 @@ describe Eventual, 'Es' do
|
|
235
234
|
describe 'with weekday constrain' do
|
236
235
|
describe "wdays for 'lunes y martes del 1 al 22 de marzo del '10" do
|
237
236
|
before do
|
238
|
-
@result =
|
237
|
+
@result = Eventual.parse "lunes y martes del 1 al 22 de marzo del '10"
|
239
238
|
@dates = (Date.parse('2010-3-1')..Date.parse('2010-3-22')).reject{ |day| not [1,2].include?(day.wday) }
|
240
239
|
end
|
241
240
|
it_should_behave_like 'correctly parses'
|
@@ -243,7 +242,7 @@ describe Eventual, 'Es' do
|
|
243
242
|
|
244
243
|
describe "wdays for 'fines de semana del 1 al 22 de marzo del '10" do
|
245
244
|
before do
|
246
|
-
@result =
|
245
|
+
@result = Eventual.parse "fines de semana del 1 al 22 de marzo del '10"
|
247
246
|
@dates = (Date.parse('2010-3-1')..Date.parse('2010-3-22')).map.reject{ |day| not [6,0].include?(day.wday) }
|
248
247
|
end
|
249
248
|
it_should_behave_like 'correctly parses'
|
@@ -251,7 +250,7 @@ describe Eventual, 'Es' do
|
|
251
250
|
|
252
251
|
describe "wdays for 'entre semana del 1 al 22 de marzo del '10" do
|
253
252
|
before do
|
254
|
-
@result =
|
253
|
+
@result = Eventual.parse("entre semana del 1 al 22 de marzo del '10")
|
255
254
|
@dates = (Date.parse('2010-3-1')..Date.parse('2010-3-22')).map.reject{ |day| not (1..5).map.include?(day.wday) }
|
256
255
|
end
|
257
256
|
it_should_behave_like 'correctly parses'
|
@@ -263,22 +262,22 @@ describe Eventual, 'Es' do
|
|
263
262
|
end
|
264
263
|
|
265
264
|
describe "wdays for 'lunes y martes del 1 al 22 de marzo del '10" do
|
266
|
-
before { @result =
|
265
|
+
before { @result = Eventual.parse("lunes y martes del 1 al 22 de marzo del '10") }
|
267
266
|
it_should_behave_like 'correctly parses'
|
268
267
|
end
|
269
268
|
|
270
269
|
describe "wdays for 'todos los lunes y martes del 1 al 22 de marzo del '10" do
|
271
|
-
before { @result =
|
270
|
+
before { @result = Eventual.parse("todos los lunes y martes del 1 al 22 de marzo del '10") }
|
272
271
|
it_should_behave_like 'correctly parses'
|
273
272
|
end
|
274
273
|
|
275
274
|
describe "wdays for 'los lunes y martes del 1 al 22 de marzo del '10" do
|
276
|
-
before { @result =
|
275
|
+
before { @result = Eventual.parse("los lunes y martes del 1 al 22 de marzo del '10") }
|
277
276
|
it_should_behave_like 'correctly parses'
|
278
277
|
end
|
279
278
|
|
280
279
|
describe "wdays for 'los lunes y los martes del 1 al 22 de marzo del '10" do
|
281
|
-
before { @result =
|
280
|
+
before { @result = Eventual.parse("los lunes y los martes del 1 al 22 de marzo del '10") }
|
282
281
|
it_should_behave_like 'correctly parses'
|
283
282
|
end
|
284
283
|
end
|
@@ -288,7 +287,7 @@ describe Eventual, 'Es' do
|
|
288
287
|
describe 'month range' do
|
289
288
|
describe 'octubre a diciembre del 2008' do
|
290
289
|
before do
|
291
|
-
@result =
|
290
|
+
@result = Eventual.parse('octubre a diciembre del 2008')
|
292
291
|
@dates = (Date.parse('2008-10-1')..DateTime.parse('2008-12-31')).map
|
293
292
|
end
|
294
293
|
it_should_behave_like 'correctly parses'
|
@@ -297,7 +296,7 @@ describe Eventual, 'Es' do
|
|
297
296
|
|
298
297
|
describe 'lunes y martes de octubre del 2007 a diciembre del 2008' do
|
299
298
|
before do
|
300
|
-
@result =
|
299
|
+
@result = Eventual.parse('lunes y martes de octubre del 2007 a diciembre del 2008')
|
301
300
|
@dates = (Date.parse('2007-10-1')..DateTime.parse('2008-12-31')).reject{ |day| not [1,2].include?(day.wday) }
|
302
301
|
end
|
303
302
|
it_should_behave_like 'correctly parses'
|
@@ -306,7 +305,7 @@ describe Eventual, 'Es' do
|
|
306
305
|
|
307
306
|
describe 'compound dates giving year at the end' do
|
308
307
|
before do
|
309
|
-
@result =
|
308
|
+
@result = Eventual.parse "1 de enero y lunes y martes del 1 de octubre al 2 de diciembre del 2008"
|
310
309
|
@dates = [Date.parse('2008-1-1')] + (Date.parse('2008-10-1')..Date.parse('2008-12-2')).reject{ |day| not [1,2].include?(day.wday) }
|
311
310
|
end
|
312
311
|
it_should_behave_like 'correctly parses'
|
@@ -314,7 +313,7 @@ describe Eventual, 'Es' do
|
|
314
313
|
|
315
314
|
describe 'compound dates in different lines' do
|
316
315
|
before do
|
317
|
-
@result =
|
316
|
+
@result = Eventual.parse "1 de enero\nlunes y martes del 1 de octubre al 2 de diciembre del 2008"
|
318
317
|
@dates = [Date.parse('2008-1-1')] + (Date.parse('2008-10-1')..Date.parse('2008-12-2')).reject{ |day| not [1,2].include?(day.wday) }
|
319
318
|
end
|
320
319
|
it_should_behave_like 'correctly parses'
|
@@ -329,7 +328,7 @@ describe Eventual, 'Es' do
|
|
329
328
|
|
330
329
|
describe 'single day with time' do
|
331
330
|
before do
|
332
|
-
@result =
|
331
|
+
@result = Eventual.parse('1 de enero del 2010 a las 15:00')
|
333
332
|
@dates = [DateTime.civil 2010, 1, 1, 15]
|
334
333
|
end
|
335
334
|
it_should_behave_like 'correctly parses'
|
@@ -338,7 +337,7 @@ describe Eventual, 'Es' do
|
|
338
337
|
|
339
338
|
describe 'single time with no sugar for month range' do
|
340
339
|
before do
|
341
|
-
@result =
|
340
|
+
@result = Eventual.parse('lunes y martes de diciembre del 2010 a las 15:00')
|
342
341
|
@dates = (DateTime.parse('2010-12-1T15:00')..DateTime.parse('2010-12-31T15:00')).reject{ |day| not [1,2].include?(day.wday) }
|
343
342
|
end
|
344
343
|
it_should_behave_like 'correctly parses'
|
@@ -347,7 +346,7 @@ describe Eventual, 'Es' do
|
|
347
346
|
|
348
347
|
describe 'single time with sugar 1 for month range' do
|
349
348
|
before do
|
350
|
-
@result =
|
349
|
+
@result = Eventual.parse('lunes y martes de diciembre a las 15:00 hrs.')
|
351
350
|
@dates = (DateTime.parse('2010-12-1T15:00')..DateTime.parse('2010-12-31T15:00')).reject{ |day| not [1,2].include?(day.wday) }
|
352
351
|
end
|
353
352
|
it_should_behave_like 'correctly parses'
|
@@ -356,7 +355,7 @@ describe Eventual, 'Es' do
|
|
356
355
|
|
357
356
|
describe 'single time with sugar 2 for month range' do
|
358
357
|
before do
|
359
|
-
@result =
|
358
|
+
@result = Eventual.parse('lunes y martes de diciembre a las 15:00hrs')
|
360
359
|
@dates = (DateTime.parse('2010-12-1T15:00')..DateTime.parse('2010-12-31T15:00')).reject{ |day| not [1,2].include?(day.wday) }
|
361
360
|
end
|
362
361
|
it_should_behave_like 'correctly parses'
|
@@ -365,7 +364,7 @@ describe Eventual, 'Es' do
|
|
365
364
|
|
366
365
|
describe 'single time with sugar 3 for month range' do
|
367
366
|
before do
|
368
|
-
@result =
|
367
|
+
@result = Eventual.parse('lunes y martes de diciembre a las 15 horas')
|
369
368
|
@dates = (DateTime.parse('2010-12-1T15:00')..DateTime.parse('2010-12-31T15:00')).reject{ |day| not [1,2].include?(day.wday) }
|
370
369
|
end
|
371
370
|
it_should_behave_like 'correctly parses'
|
@@ -374,7 +373,7 @@ describe Eventual, 'Es' do
|
|
374
373
|
|
375
374
|
describe 'two times for month range' do
|
376
375
|
before do
|
377
|
-
@result =
|
376
|
+
@result = Eventual.parse('lunes y martes de diciembre a las 16:00 y 15:00 horas')
|
378
377
|
@dates = ((DateTime.parse('2010-12-1T15:00')..DateTime.parse('2010-12-31T15:00')).map + (DateTime.parse('2010-12-1T16:00')..DateTime.parse('2010-12-31T16:00')).map).reject{ |day| not [1,2].include?(day.wday) }
|
379
378
|
end
|
380
379
|
it_should_behave_like 'correctly parses'
|
@@ -387,7 +386,7 @@ describe Eventual, 'Es' do
|
|
387
386
|
|
388
387
|
describe 'range with time as 12 hours am' do
|
389
388
|
before do
|
390
|
-
@result =
|
389
|
+
@result = Eventual.parse('lunes y martes de diciembre a las 3 am')
|
391
390
|
@dates = ((DateTime.parse('2010-12-1T03:00')..DateTime.parse('2010-12-31T03:00')).map).reject{ |day| not [1,2].include?(day.wday) }
|
392
391
|
end
|
393
392
|
it_should_behave_like 'correctly parses'
|
@@ -400,7 +399,7 @@ describe Eventual, 'Es' do
|
|
400
399
|
|
401
400
|
describe 'range with time as 12 hours pm' do
|
402
401
|
before do
|
403
|
-
@result =
|
402
|
+
@result = Eventual.parse('lunes y martes de diciembre a las 3:00 pm')
|
404
403
|
@dates = ((DateTime.parse('2010-12-1T15:00')..DateTime.parse('2010-12-31T15:00')).map).reject{ |day| not [1,2].include?(day.wday) }
|
405
404
|
end
|
406
405
|
it_should_behave_like 'correctly parses'
|
@@ -415,7 +414,7 @@ describe Eventual, 'Es' do
|
|
415
414
|
describe 'Marshal dump' do
|
416
415
|
describe "month without year parsing 'marzo'" do
|
417
416
|
before do
|
418
|
-
@result = Marshal.load Marshal.dump(
|
417
|
+
@result = Marshal.load Marshal.dump(Eventual.parse('marzo')).gsub('NaturalDates::', 'NaturalDates::Eventual::Es::')
|
419
418
|
@dates = (Date.parse('2010-3-1')..Date.parse('2010-3-31')).map
|
420
419
|
end
|
421
420
|
it_should_behave_like 'correctly parses'
|
@@ -425,8 +424,7 @@ describe Eventual, 'Es' do
|
|
425
424
|
describe 'Default year' do
|
426
425
|
describe "month without year parsing 'marzo'" do
|
427
426
|
before do
|
428
|
-
@result =
|
429
|
-
@result.year = 2007
|
427
|
+
@result = Eventual.parse('marzo', :default_year => 2007)
|
430
428
|
@dates = (Date.parse('2007-3-1')..Date.parse('2007-3-31')).map
|
431
429
|
end
|
432
430
|
it_should_behave_like 'correctly parses'
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 5
|
8
|
-
-
|
9
|
-
version: 0.5.
|
8
|
+
- 2
|
9
|
+
version: 0.5.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Macario Ortega
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-07-
|
17
|
+
date: 2010-07-20 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|