maca-eventual 0.4.5 → 0.4.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -4
- data/eventual.gemspec +2 -2
- data/lib/eventual.rb +27 -29
- data/spec/es_eventual_spec.rb +27 -13
- metadata +2 -2
data/Rakefile
CHANGED
@@ -2,16 +2,14 @@ require 'rubygems' unless ENV['NO_RUBYGEMS']
|
|
2
2
|
%w[rake rake/clean fileutils newgem rubigen].each { |f| require f }
|
3
3
|
require File.dirname(__FILE__) + '/lib/eventual'
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
|
6
|
+
|
7
7
|
$hoe = Hoe.new('eventual', Eventual::VERSION) do |p|
|
8
8
|
p.developer('Macario Ortega', 'macarui@gmail.com')
|
9
9
|
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
10
10
|
p.rubyforge_name = p.name
|
11
11
|
|
12
12
|
p.clean_globs |= %w[**/.DS_Store tmp *.log]
|
13
|
-
# path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
|
14
|
-
# p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
|
15
13
|
p.rsync_args = '-av --delete --ignore-errors'
|
16
14
|
end
|
17
15
|
|
data/eventual.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{eventual}
|
5
|
-
s.version = "0.4.
|
5
|
+
s.version = "0.4.7"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Macario Ortega"]
|
9
|
-
s.date = %q{2009-
|
9
|
+
s.date = %q{2009-09-01}
|
10
10
|
s.description = %q{}
|
11
11
|
s.email = ["macarui@gmail.com"]
|
12
12
|
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.rdoc"]
|
data/lib/eventual.rb
CHANGED
@@ -4,41 +4,40 @@ require 'strscan'
|
|
4
4
|
|
5
5
|
$:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
6
6
|
|
7
|
-
|
8
7
|
module Eventual
|
9
|
-
VERSION = '0.4.
|
8
|
+
VERSION = '0.4.7'
|
10
9
|
extend self
|
11
10
|
|
12
11
|
WDAY_LIST = %w(domingo lunes martes miercoles jueves viernes sabado)
|
13
12
|
MNAMES = %w(enero febrero marzo abril mayo junio julio agosto septiembre octubre noviembre diciembre).unshift(nil)
|
14
13
|
|
15
|
-
year = /(?: (?:del|de))? (\d{4})/
|
16
|
-
horarios = / a las (.*)/
|
14
|
+
year = /(?: (?:del|de))? (\d{4})/i
|
15
|
+
horarios = / a las (.*)/i
|
17
16
|
DAY_LIST = %r{
|
18
17
|
(
|
19
18
|
(?:
|
20
19
|
\d{1,2}
|
21
|
-
(?-
|
20
|
+
(?-x: |, | y )
|
22
21
|
)+ # Lista de número de día
|
23
22
|
)
|
24
|
-
de\s(#{ MNAMES.compact.join('|') }) #
|
23
|
+
de\s(#{ MNAMES.compact.join('|') }) # Mes
|
25
24
|
(?:#{ year })? # Año opcional
|
26
25
|
(#{ horarios })? # Hora opcional
|
27
26
|
}ixo
|
28
27
|
|
29
28
|
DAY_PERIOD = %r{
|
30
29
|
(
|
31
|
-
(?: #
|
30
|
+
(?: # Dias de la semana opcionales
|
32
31
|
(?:#{ WDAY_LIST.join('|') }) # Nombre del día
|
33
|
-
(?-
|
32
|
+
(?-x: |, | y ) # Concatenador
|
34
33
|
)*
|
35
34
|
)
|
36
|
-
(?-
|
37
|
-
(?:de\s
|
35
|
+
(?-x:del (\d{1,2}))\s # Comienzo del periodo
|
36
|
+
(?:de\s # Mes opcional
|
38
37
|
(#{ MNAMES.compact.join('|') }) # Nombre del mes
|
39
38
|
(?:#{ year })? # Año opcional
|
40
39
|
\s)?
|
41
|
-
(?-
|
40
|
+
(?-x:al (\d{1,2}) de (#{ MNAMES.compact.join('|') })) # Mes requerido
|
42
41
|
(?:#{ year })? # Año opcional
|
43
42
|
(#{ horarios })? # Hora opcional
|
44
43
|
}ixo
|
@@ -46,7 +45,7 @@ module Eventual
|
|
46
45
|
def event_parse string, opts = {}, &block
|
47
46
|
parser = opts.delete(:parser) || (self == Eventual ? DateTime : self)
|
48
47
|
use_trailing = opts.delete(:use_trailing)
|
49
|
-
string = Iconv.iconv("ASCII//IGNORE//TRANSLIT", "UTF-8", string).join.gsub(/'/, '')
|
48
|
+
string = Iconv.iconv("ASCII//IGNORE//TRANSLIT", "UTF-8", string).join.gsub(/'/, '').gsub(/(\s)+/, '\1')
|
50
49
|
results = []
|
51
50
|
scanner = StringScanner.new string
|
52
51
|
|
@@ -56,12 +55,13 @@ module Eventual
|
|
56
55
|
when DAY_PERIOD
|
57
56
|
wdays, first_day, first_month, first_year, last_day, last_month, last_year, times = $1, $2, $3, $4, $5, $6, $7, $8
|
58
57
|
match = $&
|
59
|
-
wdays = wdays.scan( Regexp.new(WDAY_LIST.join('|')) ).collect{ |d| WDAY_LIST.index d }
|
58
|
+
wdays = wdays.scan( Regexp.new(WDAY_LIST.join('|')) ).collect{ |d| WDAY_LIST.index d.downcase }
|
60
59
|
last_year ||= string.match(/\d{4}/) ? $& : Date.today.year
|
61
60
|
first_year ||= last_year
|
62
61
|
first_month ||= last_month
|
63
|
-
last_month = MNAMES.index last_month
|
64
|
-
first_month = MNAMES.index first_month
|
62
|
+
last_month = MNAMES.index last_month.downcase
|
63
|
+
first_month = MNAMES.index first_month.downcase
|
64
|
+
|
65
65
|
make_days = lambda do |hour, minute|
|
66
66
|
first = make_day parser, first_year, first_month, first_day, hour, minute
|
67
67
|
last = make_day parser, last_year, last_month, last_day, hour, minute
|
@@ -73,42 +73,40 @@ module Eventual
|
|
73
73
|
end
|
74
74
|
|
75
75
|
when DAY_LIST
|
76
|
-
days, month, year, times = $1, MNAMES.index($2), $3, $4
|
76
|
+
days, month, year, times = $1, MNAMES.index($2.downcase), $3, $4
|
77
77
|
match = $&
|
78
78
|
days = days.scan(/\d{1,2}/)
|
79
79
|
year ||= string.match(/\d{4}/) ? $& : Date.today.year
|
80
|
+
|
80
81
|
make_days = lambda do |hour, minute|
|
81
82
|
days.map do |day|
|
82
83
|
make_day parser, year, month, day, hour, minute
|
83
84
|
end
|
84
85
|
end
|
86
|
+
|
85
87
|
else
|
86
88
|
break
|
87
89
|
end
|
88
90
|
|
89
|
-
extra = scanner.scan(/.*?(?=#{DAY_LIST}|#{DAY_PERIOD}|\
|
90
|
-
|
91
|
+
extra = scanner.scan(/.*?(?=#{DAY_LIST}|#{DAY_PERIOD}|\z)/m).to_s.chomp
|
92
|
+
extra.gsub!(/^(,|\n|\.)/, '')
|
93
|
+
|
94
|
+
days =
|
91
95
|
if times
|
92
|
-
times.scan( /(\d{2}):(\d{2})/ ).map
|
93
|
-
make_days.call hour, minute
|
94
|
-
end.flatten
|
96
|
+
times.scan( /(\d{2}):(\d{2})/ ).map{ |hour, minute| make_days.call hour, minute }.flatten
|
95
97
|
else
|
96
98
|
make_days.call nil, nil
|
97
99
|
end
|
100
|
+
|
101
|
+
days.each { |day| day.instance_variable_set('@extra', extra) }
|
102
|
+
results += days
|
98
103
|
end
|
99
104
|
|
100
105
|
raise ArgumentError.new( 'El formato de las fechas parece ser incorrecto' ) if results.empty?
|
101
106
|
results.uniq!
|
102
107
|
results.sort!
|
103
108
|
|
104
|
-
results.map!
|
105
|
-
if use_trailing
|
106
|
-
yield day, extra.to_s.gsub(/^[\n|.|,]*/, '')
|
107
|
-
else
|
108
|
-
yield day
|
109
|
-
end
|
110
|
-
end if block_given?
|
111
|
-
|
109
|
+
use_trailing ? results.map!{ |day| yield day, day.instance_variable_get('@extra') } : results.map!{ |day| yield day } if block_given?
|
112
110
|
results
|
113
111
|
end
|
114
112
|
|
data/spec/es_eventual_spec.rb
CHANGED
@@ -62,18 +62,7 @@ describe 'event parsing' do
|
|
62
62
|
e.should map_times( *r )
|
63
63
|
end
|
64
64
|
|
65
|
-
|
66
|
-
e = Eventual.event_parse( 'martes y jueves del 1 de enero del 2000 al 31 de diciembre del 2010' )
|
67
|
-
r = (DateTime.parse('2000-1-1T00:00')..DateTime.parse('2010-12-31T00:00') ).reject{ |day| not [2,4].include?(day.wday) }
|
68
|
-
e.should map_times( *r )
|
69
|
-
end
|
70
|
-
|
71
|
-
it "should parse a long period with multiple times" do
|
72
|
-
e = Eventual.event_parse( 'martes y jueves del 1 de enero del 2000 al 31 de diciembre del 2010 a las 16:00 y 18:00 horas' )
|
73
|
-
r = (DateTime.parse('2000-1-1T16:00')...DateTime.parse('2010-12-31T16:00') ).reject{ |day| not [2,4].include?(day.wday) } +
|
74
|
-
(DateTime.parse('2000-1-1T18:00')...DateTime.parse('2010-12-31T18:00') ).reject{ |day| not [2,4].include?(day.wday) }
|
75
|
-
e.should map_times( *r.sort )
|
76
|
-
end
|
65
|
+
|
77
66
|
|
78
67
|
it "should event_parse a period with block" do
|
79
68
|
Eventual.event_parse( 'del 5 al 7 de junio 2009' ){ |d| Eventual::WDAY_LIST[ d.wday ] }.should == ['viernes', 'sabado', 'domingo']
|
@@ -108,13 +97,38 @@ describe 'event parsing' do
|
|
108
97
|
end.should == ['viernes', 'sabado', 'domingo']
|
109
98
|
end
|
110
99
|
|
111
|
-
it "should event_parse a several dates" do
|
100
|
+
it "should event_parse a several dates" do
|
112
101
|
Eventual.event_parse( "1 de enero del 2009\nSede:El tercer lugar\nCupo: limitado\n2 de enero del 2009\nSede:El tercer lugar\nCupo: limitado", :use_trailing => true ) do |d, extra|
|
113
102
|
extra.should == "Sede:El tercer lugar\nCupo: limitado"
|
114
103
|
d.to_s
|
115
104
|
end.should == ["2009-01-01T00:00:00+00:00", "2009-01-02T00:00:00+00:00"]
|
116
105
|
end
|
106
|
+
|
107
|
+
it "should event_parse a several dates" do
|
108
|
+
Eventual.event_parse( "1 de enero del 2009\nSede 1\n\n2 de enero del 2009\nSede 2", :use_trailing => true ) do |d, extra|
|
109
|
+
[d.to_s, extra]
|
110
|
+
end.should == [["2009-01-01T00:00:00+00:00", "Sede 1"], ["2009-01-02T00:00:00+00:00", "Sede 2"]]
|
111
|
+
end
|
117
112
|
end
|
118
113
|
|
114
|
+
describe 'Case sensitivity' do
|
115
|
+
it "should ignore case" do
|
116
|
+
Eventual.event_parse( 'DeL 1 al 3 de ENeRO' ).should map_times( '2009-1-1', '2009-1-2', '2009-1-3' )
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
# it "should parse a long period" do
|
121
|
+
# e = Eventual.event_parse( 'martes y jueves del 1 de enero del 2000 al 31 de diciembre del 2010' )
|
122
|
+
# r = (DateTime.parse('2000-1-1T00:00')..DateTime.parse('2010-12-31T00:00') ).reject{ |day| not [2,4].include?(day.wday) }
|
123
|
+
# e.should map_times( *r )
|
124
|
+
# end
|
125
|
+
#
|
126
|
+
# it "should parse a long period with multiple times" do
|
127
|
+
# e = Eventual.event_parse( 'martes y jueves del 1 de enero del 2000 al 31 de diciembre del 2010 a las 16:00 y 18:00 horas' )
|
128
|
+
# r = (DateTime.parse('2000-1-1T16:00')...DateTime.parse('2010-12-31T16:00') ).reject{ |day| not [2,4].include?(day.wday) } +
|
129
|
+
# (DateTime.parse('2000-1-1T18:00')...DateTime.parse('2010-12-31T18:00') ).reject{ |day| not [2,4].include?(day.wday) }
|
130
|
+
# e.should map_times( *r.sort )
|
131
|
+
# end
|
132
|
+
|
119
133
|
end
|
120
134
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: maca-eventual
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Macario Ortega
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-09-01 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|