texp 0.0.7 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,19 +1,14 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'test/unit'
4
- require 'date'
5
- require 'texp'
6
- require 'flexmock/test_unit'
1
+ require 'test_helper'
7
2
 
8
3
  ######################################################################
9
- class InspectTest < Test::Unit::TestCase
4
+ class InspectTest < Minitest::Test
10
5
  def test_inspect
11
6
  assert_inspect "e", "every day"
12
7
 
13
- assert_inspect "0w", "the day of the week is Sunday"
14
- assert_inspect "[0,1]w", "the day of the week is Sunday or Monday"
8
+ assert_inspect "0w", "on Sunday"
9
+ assert_inspect "[0,1]w", "on Sunday and Monday"
15
10
  assert_inspect "[0,1,4,2,3,6,5]w",
16
- "the day of the week is Sunday, Monday, Tuesday, Wednesday, Thursday, Friday or Saturday"
11
+ "on Sunday, Monday, Tuesday, Wednesday, Thursday, Friday and Saturday"
17
12
 
18
13
  assert_inspect "1d", "the day of the month is the 1st"
19
14
  assert_inspect "2d", "the day of the month is the 2nd"
@@ -33,8 +28,8 @@ class InspectTest < Test::Unit::TestCase
33
28
  assert_inspect "20d", "the day of the month is the 20th"
34
29
  assert_inspect "[1,10,15]d", "the day of the month is the 1st, 10th or 15th"
35
30
 
36
- assert_inspect "2008-02-15,3i", "every 3rd day starting on February 15, 2008"
37
- assert_inspect "2008-02-15,1i", "every day starting on February 15, 2008"
31
+ assert_inspect "2008-02-15,3i", "every 3 days"
32
+ assert_inspect "2008-02-15,1i", "every day"
38
33
 
39
34
  assert_inspect "1k", "it is the 1st week of the month"
40
35
  assert_inspect "[1,3]k", "it is the 1st or 3rd week of the month"
@@ -56,7 +51,7 @@ class InspectTest < Test::Unit::TestCase
56
51
  "it is not the case that the day of the month is the 1st or the month is January"
57
52
 
58
53
  assert_inspect "3w2,1s",
59
- "the day of the week is Wednesday, or up to 2 days prior, or up to 1 day after"
54
+ "on Wednesday, or up to 2 days prior, or up to 1 day after"
60
55
  end
61
56
 
62
57
  def assert_inspect(texp, string)
@@ -1,10 +1,6 @@
1
- #!/usr/bin/env ruby
1
+ require 'test_helper'
2
2
 
3
- require 'test/unit'
4
- require 'date'
5
- require 'texp'
6
-
7
- class LogicTest < Test::Unit::TestCase
3
+ class LogicTest < Minitest::Test
8
4
 
9
5
  DATE = Date.parse("Feb 14, 2008")
10
6
  LEFT = TExp::DayInterval.new(DATE, 2)
@@ -48,4 +44,3 @@ class LogicTest < Test::Unit::TestCase
48
44
  end
49
45
 
50
46
  end
51
-
@@ -1,10 +1,6 @@
1
- #!/usr/bin/env ruby
1
+ require 'test_helper'
2
2
 
3
- require 'test/unit'
4
- require 'date'
5
- require 'texp'
6
-
7
- class MonthTest < Test::Unit::TestCase
3
+ class MonthTest < Minitest::Test
8
4
 
9
5
  def setup
10
6
  @date = Date.parse("Feb 14, 2008")
@@ -17,4 +13,3 @@ class MonthTest < Test::Unit::TestCase
17
13
  assert ! te.includes?(@date + 30)
18
14
  end
19
15
  end
20
-
@@ -1,9 +1,6 @@
1
- #!/usr/bin/env ruby
1
+ require 'test_helper'
2
2
 
3
- require 'test/unit'
4
- require 'texp'
5
-
6
- class OperatorsTest < Test::Unit::TestCase
3
+ class OperatorsTest < Minitest::Test
7
4
  def setup
8
5
  @monday = Date.parse("Mar 3, 2008")
9
6
  @tuesday = Date.parse("Mar 4, 2008")
@@ -1,16 +1,20 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'test/unit'
4
- require 'date'
5
- require 'texp'
6
- require 'flexmock/test_unit'
1
+ require 'test_helper'
7
2
 
8
3
  ######################################################################
9
- class TExpParseLexicalTest < Test::Unit::TestCase
4
+ class TExpParseLexicalTest < Minitest::Test
5
+ XTEXP = class << TExp; self; end
6
+
10
7
  def setup
8
+ @compile_method = TExp.method(:compile)
11
9
  @tokens = []
12
- flexmock(TExp).should_receive(:compile).with(any).
13
- and_return { |tok| @tokens << tok }
10
+ tk = @tokens
11
+ XTEXP.send(:define_method, :compile) { |tok|
12
+ tk << tok
13
+ }
14
+ end
15
+
16
+ def teardown
17
+ XTEXP.send(:define_method, :compile, @compile_method)
14
18
  end
15
19
 
16
20
  def test_letters
@@ -49,7 +53,7 @@ class TExpParseLexicalTest < Test::Unit::TestCase
49
53
  '[', '[', '2008', 'y', '2', 'm', '14', 'd', ']', 'a', '12', 'm',
50
54
  '[', '1', '15', ']', 'd', '2008-02-14', '3', 'i', ']', 'o'
51
55
  ]
52
-
56
+
53
57
  def test_mixed
54
58
  assert_lex "[[2008y2m14d]a12m[1,15]d2008-02-14,3i]o", *EXPECTED
55
59
  end
@@ -68,25 +72,25 @@ end
68
72
 
69
73
 
70
74
  ######################################################################
71
- class ParseTest < Test::Unit::TestCase
75
+ class ParseTest < Minitest::Test
72
76
  def setup
73
77
  @date = Date.parse("Feb 14, 2008")
74
78
  end
75
79
 
76
80
  def test_bad_parse_string
77
- assert_raise TExp::ParseError do
81
+ assert_raises TExp::ParseError do
78
82
  TExp.parse("(1,2)d")
79
83
  end
80
84
  end
81
85
 
82
86
  def test_unbalanced_list
83
- assert_raise TExp::ParseError do
87
+ assert_raises TExp::ParseError do
84
88
  TExp.parse("[1")
85
89
  end
86
90
  end
87
91
 
88
92
  def test_unbalanced_list2
89
- assert_raise TExp::ParseError do
93
+ assert_raises TExp::ParseError do
90
94
  TExp.parse("1]")
91
95
  end
92
96
  end
@@ -197,7 +201,7 @@ class ParseTest < Test::Unit::TestCase
197
201
  end
198
202
 
199
203
  ######################################################################
200
- class ParseReverseTest < Test::Unit::TestCase
204
+ class ParseReverseTest < Minitest::Test
201
205
  def setup
202
206
  @date = Date.parse("Feb 14, 2008")
203
207
  end
@@ -230,4 +234,3 @@ class ParseReverseTest < Test::Unit::TestCase
230
234
  assert_equal string, te.to_s
231
235
  end
232
236
  end
233
-
@@ -1,7 +1,6 @@
1
- require 'test/texp_tests'
2
- require 'texp'
1
+ require 'test_helper'
3
2
 
4
- class TimeExtTest < Test::Unit::TestCase
3
+ class TimeExtTest < Minitest::Test
5
4
  def test_time_to_date
6
5
  assert_equal Date.today, Time.now.to_date
7
6
  end
@@ -0,0 +1,32 @@
1
+ require 'test_helper'
2
+
3
+ class WeekIntervalTest < Minitest::Test
4
+
5
+ def test_week_interval
6
+ te = TExp::WeekInterval.new(Date.parse("Feb 10, 2008"), 1)
7
+ assert ! te.includes?(Date.parse("Feb 9, 2008"))
8
+ assert te.includes?(Date.parse("Feb 10, 2008"))
9
+ assert ! te.includes?(Date.parse("Feb 11, 2008"))
10
+ assert ! te.includes?(Date.parse("Feb 12, 2008"))
11
+ assert ! te.includes?(Date.parse("Feb 16, 2008"))
12
+ assert te.includes?(Date.parse("Feb 17, 2008"))
13
+ assert ! te.includes?(Date.parse("Feb 18, 2008"))
14
+ assert ! te.includes?(Date.parse("Feb 23, 2008"))
15
+ assert te.includes?(Date.parse("Feb 24, 2008"))
16
+ assert ! te.includes?(Date.parse("Feb 25, 2008"))
17
+ end
18
+
19
+ def test_day_interval_without_start_date
20
+ te = TExp::DayInterval.new(0, 3)
21
+ assert ! te.includes?(Date.parse("Feb 10, 2008"))
22
+ assert_equal "0,3i", te.to_s
23
+ assert_equal "0,3i", TExp.parse("0,3i").to_s
24
+ end
25
+
26
+ def test_day_interval_excludes_dates_before_start
27
+ date = d("Mar 1, 2008")
28
+ te = TExp::DayInterval.new(date, 3)
29
+
30
+ assert_not_includes te, date-3, date-2, date-1
31
+ end
32
+ end
@@ -1,10 +1,6 @@
1
- #!/usr/bin/env ruby
1
+ require 'test_helper'
2
2
 
3
- require 'date'
4
- require 'test/unit'
5
- require 'texp'
6
-
7
- class WeekTest < Test::Unit::TestCase
3
+ class WeekTest < Minitest::Test
8
4
 
9
5
  def test_week_include_with_one_week
10
6
  te = TExp::Week.new([1])
@@ -55,4 +51,3 @@ class WeekTest < Test::Unit::TestCase
55
51
  assert_equal 31, te.send(:last_day_of_month, Date.parse("Dec 1, 2007"))
56
52
  end
57
53
  end
58
-
@@ -1,10 +1,6 @@
1
- #!/usr/bin/env ruby
1
+ require 'test_helper'
2
2
 
3
- require 'date'
4
- require 'test/unit'
5
- require 'texp'
6
-
7
- class WindowTest < Test::Unit::TestCase
3
+ class WindowTest < Minitest::Test
8
4
 
9
5
  def test_window
10
6
  wed = TExp.parse("3w")
@@ -58,4 +54,3 @@ class WindowTest < Test::Unit::TestCase
58
54
  end
59
55
 
60
56
  end
61
-
@@ -1,10 +1,6 @@
1
- #!/usr/bin/env ruby
1
+ require 'test_helper'
2
2
 
3
- require 'test/unit'
4
- require 'date'
5
- require 'texp'
6
-
7
- class YearTest < Test::Unit::TestCase
3
+ class YearTest < Minitest::Test
8
4
 
9
5
  def setup
10
6
  @date = Date.parse("Feb 14, 2008")
@@ -17,7 +13,7 @@ class YearTest < Test::Unit::TestCase
17
13
  assert ! te.includes?(@date + 365)
18
14
  end
19
15
 
20
- def test_single_arg
16
+ def test_two_args
21
17
  te = TExp::Year.new([2007,2008])
22
18
  assert te.includes?(@date - 365)
23
19
  assert te.includes?(@date)
@@ -25,4 +21,3 @@ class YearTest < Test::Unit::TestCase
25
21
  assert ! te.includes?(@date + 365)
26
22
  end
27
23
  end
28
-
@@ -1,4 +1,4 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'texp'
3
3
 
4
4
  # Convenience method for parsing dates.
@@ -22,6 +22,6 @@ module TExpAssertions
22
22
  end
23
23
  end
24
24
 
25
- class Test::Unit::TestCase
25
+ class Minitest::Test
26
26
  include TExpAssertions
27
27
  end
metadata CHANGED
@@ -1,55 +1,56 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: texp
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.7
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Jim Weirich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
-
12
- date: 2008-03-10 00:00:00 -04:00
13
- default_executable:
11
+ date: 2013-06-10 00:00:00.000000000 Z
14
12
  dependencies: []
15
-
16
- description: TExp is a temporal expression library for Ruby with a modular, extensible expression serialization language.
13
+ description: |2
14
+ TExp is a temporal expression library for Ruby with a modular,
15
+ extensible expression serialization language.
17
16
  email: jim.weirich@gmail.com
18
17
  executables: []
19
-
20
18
  extensions: []
21
-
22
- extra_rdoc_files:
23
- - README
19
+ extra_rdoc_files:
20
+ - README.rdoc
24
21
  - MIT-LICENSE
25
22
  - ChangeLog
26
- files:
23
+ files:
27
24
  - ChangeLog
25
+ - Gemfile
26
+ - Gemfile.lock
28
27
  - INFO
29
28
  - MIT-LICENSE
29
+ - README.rdoc
30
30
  - Rakefile
31
- - README
32
31
  - TAGS
33
32
  - lib/texp.rb
34
33
  - lib/texp/base.rb
35
- - lib/texp/builder.rb
36
34
  - lib/texp/day_interval.rb
37
35
  - lib/texp/day_of_month.rb
38
36
  - lib/texp/day_of_week.rb
37
+ - lib/texp/day_of_week_interval.rb
39
38
  - lib/texp/dsl.rb
40
39
  - lib/texp/errors.rb
41
40
  - lib/texp/every_day.rb
42
41
  - lib/texp/ext.rb
43
42
  - lib/texp/logic.rb
44
43
  - lib/texp/month.rb
44
+ - lib/texp/month_interval.rb
45
45
  - lib/texp/operators.rb
46
46
  - lib/texp/parse.rb
47
47
  - lib/texp/time_ext.rb
48
48
  - lib/texp/version.rb
49
49
  - lib/texp/week.rb
50
+ - lib/texp/week_interval.rb
50
51
  - lib/texp/window.rb
51
52
  - lib/texp/year.rb
52
- - test/texp_tests.rb
53
+ - test/test_helper.rb
53
54
  - test/texp/base_test.rb
54
55
  - test/texp/day_interval_test.rb
55
56
  - test/texp/day_of_month_test.rb
@@ -63,40 +64,39 @@ files:
63
64
  - test/texp/operators_test.rb
64
65
  - test/texp/parse_test.rb
65
66
  - test/texp/time_ext_test.rb
67
+ - test/texp/week_interval_test.rb
66
68
  - test/texp/week_test.rb
67
69
  - test/texp/window_test.rb
68
70
  - test/texp/year_test.rb
71
+ - test/texp_tests.rb
69
72
  - doc/jamis.rb
70
- has_rdoc: true
71
73
  homepage: http://texp.rubyforge.org
74
+ licenses: []
75
+ metadata: {}
72
76
  post_install_message:
73
- rdoc_options:
77
+ rdoc_options:
74
78
  - --line-numbers
75
79
  - --inline-source
76
80
  - --main
77
- - README
81
+ - README.rdoc
78
82
  - --title
79
83
  - TExp - Temporal Expressions
80
- require_paths:
84
+ require_paths:
81
85
  - lib
82
- required_ruby_version: !ruby/object:Gem::Requirement
83
- requirements:
84
- - - ">="
85
- - !ruby/object:Gem::Version
86
- version: "0"
87
- version:
88
- required_rubygems_version: !ruby/object:Gem::Requirement
89
- requirements:
90
- - - ">="
91
- - !ruby/object:Gem::Version
92
- version: "0"
93
- version:
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
94
96
  requirements: []
95
-
96
97
  rubyforge_project: texp
97
- rubygems_version: 1.0.1
98
+ rubygems_version: 2.0.3
98
99
  signing_key:
99
- specification_version: 2
100
+ specification_version: 4
100
101
  summary: Temporal Expressions for Ruby.
101
102
  test_files: []
102
-
@@ -1,254 +0,0 @@
1
- module TExp
2
-
3
- # Builder methods are available as methods on TExp
4
- # (e.g. +TExp.day()+). Alternatively, you can include the
5
- # +TExp::Builder+ module into whatever namespace to get direct
6
- # access to these methods.
7
- module Builder
8
-
9
- # Return a temporal expression that matches any date that falls on
10
- # a day of the month given in the argument list.
11
- # Examples:
12
- #
13
- # day(1) # Match any date that falls on the 1st of any month
14
- # day(1, 15) # Match any date that falls on the 1st or 15th of any month
15
- #
16
- def day(*days_of_month)
17
- TExp::DayOfMonth.new(days_of_month)
18
- end
19
-
20
- # Return a temporal expression that matches any date in the
21
- # specified week of the month. Days 1 through 7 are considered
22
- # the first week of the month; days 8 through 14 are the second
23
- # week; and so on.
24
- #
25
- # The week is specified by a numeric argument. Negative arguments
26
- # are calculated from the end of the month (e.g. -1 would request
27
- # the _last_ 7 days of the month). The symbols <tt>:first</tt>,
28
- # <tt>:second</tt>, <tt>:third</tt>, <tt>:fourth</tt>,
29
- # <tt>:fifth</tt>, and <tt>:last</tt> are also recognized.
30
- #
31
- # Examples:
32
- #
33
- # week(1) # Match any date in the first 7 days of any month.
34
- # week(1, 2) # Match any date in the first or second 7 days of any month.
35
- # week(:first) # Match any date in the first 7 days of any month.
36
- # week(:last) # Match any date in the last 7 days of any month.
37
- #
38
- def week(*weeks)
39
- TExp::Week.new(weeks)
40
- end
41
-
42
- # Return a temporal expression that matches any date in the list
43
- # of given months.
44
- #
45
- # <b>Examples:</b>
46
- #
47
- # month(2) # Match any date in February
48
- # month(2, 8) # Match any date in February or August
49
- # month("February") # Match any date in February
50
- # month("Sep", "Apr", "Jun", "Nov")
51
- # # Match any date in any month with 30 days.
52
- #
53
- def month(*month)
54
- TExp::Month.new(month)
55
- end
56
-
57
- # Return a temporal expression that matches the given list of
58
- # years.
59
- #
60
- # <b>Examples:</b>
61
- #
62
- # year(2008) # Match any date in 2008
63
- # year(2000, 2004, 2008) # Match any date in any of the three years
64
- def year(*years)
65
- TExp::Year.new(years)
66
- end
67
-
68
- # :call-seq:
69
- # on(day, month)
70
- # on(day, month_string)
71
- # on(day, month, year)
72
- # on(day, month_string, year)
73
- # on(date)
74
- # on(date_string)
75
- # on(time)
76
- # on(object_with_to_date)
77
- # on(object_with_to_s)
78
- #
79
- # Return a temporal expression that matches a particular date of
80
- # the year. The temporal expression will be pinned to a
81
- # particular year if a year is given (either explicity as a
82
- # parameter or implicitly via a +Date+ object). If no year is
83
- # given, then the temporal expression will match that date in any
84
- # year.
85
- #
86
- # If only a single argument is given, then the argument may be a
87
- # string (which is parsed), a Date, a Time, or an object that
88
- # responds to +to_date+. If the single argument is none of the
89
- # above, then it is converted to a string (via +to_s+) and given
90
- # to <tt>Date.parse()</tt>.
91
- #
92
- # Invalid arguments will cause +on+ to throw an ArgumentError
93
- # exception.
94
- #
95
- # <b>Examples:</b>
96
- #
97
- # The following examples all match Feb 14 of any year.
98
- #
99
- # on(14, 2)
100
- # on(14, "February")
101
- # on(14, "Feb")
102
- # on(14, :feb)
103
- #
104
- # The following examples all match Feb 14 of the year 2008.
105
- #
106
- # on(14, 2, 2008)
107
- # on(14, "February", 2008)
108
- # on(14, "Feb", 2008)
109
- # on(14, :feb, 2008)
110
- # on("Feb 14, 2008")
111
- # on(Date.new(2008, 2, 14))
112
- #
113
- def on(*args)
114
- if args.size == 1
115
- arg = args.first
116
- case arg
117
- when String
118
- date = Date.parse(arg)
119
- when Date
120
- date = arg
121
- else
122
- if arg.respond_to?(:to_date)
123
- date = arg.to_date
124
- else
125
- date = try_parsing(arg.to_s)
126
- end
127
- end
128
- on(date.day, date.month, date.year)
129
- elsif args.size == 2
130
- day, month = dm_args(args)
131
- TExp::And.new(
132
- TExp::DayOfMonth.new(day),
133
- TExp::Month.new(month))
134
- elsif args.size == 3
135
- day, month, year = dmy_args(args)
136
- TExp::And.new(
137
- TExp::DayOfMonth.new(day),
138
- TExp::Month.new(normalize_month(month)),
139
- TExp::Year.new(year))
140
- else
141
- fail DateArgumentError
142
- end
143
- rescue DateArgumentError
144
- fail ArgumentError, "Invalid arguents for on(): #{args.inspect}"
145
- end
146
-
147
- # Return a temporal expression matching the given days of the
148
- # week.
149
- #
150
- # <b>Examples:</b>
151
- #
152
- # dow(2) # Match any date on a Tuesday
153
- # dow("Tuesday") # Match any date on a Tuesday
154
- # dow(:mon, :wed, :fr) # Match any date on a Monday, Wednesday or Friday
155
- #
156
- def dow(*dow)
157
- TExp::DayOfWeek.new(normalize_dows(dow))
158
- end
159
-
160
- # Return a temporal expression that matches
161
- def every(n, unit, start_date=Date.today)
162
- value = apply_units(unit, n)
163
- TExp::DayInterval.new(start_date, value)
164
- end
165
-
166
- def normalize_units(args) # :nodoc:
167
- result = []
168
- while ! args.empty?
169
- arg = args.shift
170
- case arg
171
- when Numeric
172
- result.push(arg)
173
- when Symbol
174
- result.push(apply_units(arg, result.pop))
175
- else
176
- fail ArgumentError, "Unabled to recognize #{arg}"
177
- end
178
- end
179
- result
180
- end
181
-
182
- private
183
-
184
- MONTHNAMES = Date::MONTHNAMES.collect { |mn| mn ? mn[0,3].downcase : nil }
185
- DAYNAMES = Date::DAYNAMES.collect { |dn| dn[0,2].downcase }
186
-
187
- UNIT_MULTIPLIERS = {
188
- :day => 1, :days => 1,
189
- :week => 7, :weeks => 7,
190
- :month => 30, :months => 30,
191
- :year => 365, :years => 365,
192
- }
193
-
194
- def apply_units(unit, value)
195
- UNIT_MULTIPLIERS[unit] * value
196
- end
197
-
198
- def try_parsing(string)
199
- Date.parse(string)
200
- rescue ArgumentError
201
- fail DateArgumentError
202
- end
203
-
204
- def dm_args(args)
205
- day, month = args
206
- month = normalize_month(month)
207
- check_valid_day_month(day, month)
208
- [day, month]
209
- end
210
-
211
- def dmy_args(args)
212
- day, month, year = args
213
- month = normalize_month(month)
214
- check_valid_day_month(day, month)
215
- [day, month, year]
216
- end
217
-
218
- def check_valid_day_month(day, month)
219
- unless day.kind_of?(Integer) &&
220
- month.kind_of?(Integer) &&
221
- month >= 1 &&
222
- month <= 12 &&
223
- day >= 1 &&
224
- day <= 31
225
- fail DateArgumentError
226
- end
227
- end
228
-
229
- def normalize_month(month_thing)
230
- case month_thing
231
- when Integer
232
- month_thing
233
- else
234
- MONTHNAMES.index(month_thing.to_s[0,3].downcase)
235
- end
236
- end
237
-
238
- def normalize_dows(dow_list)
239
- dow_list.collect { |dow| normalize_dow(dow) }
240
- end
241
-
242
- def normalize_dow(dow_thing)
243
- case dow_thing
244
- when Integer
245
- dow_thing
246
- else
247
- DAYNAMES.index(dow_thing.to_s[0,2].downcase)
248
- end
249
- end
250
-
251
- end
252
-
253
- extend Builder
254
- end