hiccup 0.5.14 → 0.5.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hiccup.rb +17 -17
  3. data/lib/hiccup/convenience.rb +9 -9
  4. data/lib/hiccup/core_ext/date.rb +7 -7
  5. data/lib/hiccup/core_ext/duration.rb +4 -4
  6. data/lib/hiccup/core_ext/enumerable.rb +2 -2
  7. data/lib/hiccup/core_ext/fixnum.rb +2 -2
  8. data/lib/hiccup/core_ext/hash.rb +2 -2
  9. data/lib/hiccup/enumerable.rb +43 -29
  10. data/lib/hiccup/enumerable/annually_enumerator.rb +23 -23
  11. data/lib/hiccup/enumerable/monthly_date_enumerator.rb +2 -2
  12. data/lib/hiccup/enumerable/monthly_enumerator.rb +40 -40
  13. data/lib/hiccup/enumerable/never_enumerator.rb +8 -8
  14. data/lib/hiccup/enumerable/schedule_enumerator.rb +39 -39
  15. data/lib/hiccup/enumerable/weekly_enumerator.rb +30 -30
  16. data/lib/hiccup/errors.rb +4 -0
  17. data/lib/hiccup/humanizable.rb +19 -19
  18. data/lib/hiccup/inferable.rb +30 -30
  19. data/lib/hiccup/inferable/dates_enumerator.rb +6 -6
  20. data/lib/hiccup/inferable/guesser.rb +21 -21
  21. data/lib/hiccup/inferable/score.rb +7 -7
  22. data/lib/hiccup/inferable/scorer.rb +19 -19
  23. data/lib/hiccup/schedule.rb +10 -10
  24. data/lib/hiccup/serializable/ical.rb +13 -13
  25. data/lib/hiccup/serializers/ical.rb +59 -59
  26. data/lib/hiccup/validatable.rb +23 -23
  27. data/lib/hiccup/version.rb +1 -1
  28. data/test/core_ext_date_test.rb +5 -5
  29. data/test/duration_ext_test.rb +8 -8
  30. data/test/enumerable_test.rb +103 -103
  31. data/test/humanizable_test.rb +24 -24
  32. data/test/ical_serializable_test.rb +29 -29
  33. data/test/inferrable_test.rb +84 -84
  34. data/test/leap_year_test.rb +7 -7
  35. data/test/monthly_enumerator_test.rb +13 -13
  36. data/test/performance_test.rb +7 -7
  37. data/test/validatable_test.rb +1 -1
  38. data/test/weekly_enumerator_test.rb +38 -38
  39. metadata +4 -3
@@ -3,18 +3,18 @@ require "test_helper"
3
3
 
4
4
  class LeapYearTest < ActiveSupport::TestCase
5
5
  include Hiccup
6
-
7
-
8
-
6
+
7
+
8
+
9
9
  test "should correctly determine whether a year is a leap year or not" do
10
10
  enum = Enumerable::ScheduleEnumerator.new(Schedule.new, Date.today)
11
-
11
+
12
12
  assert enum.send(:leap_year?, 1988), "1988 is a leap year"
13
13
  assert enum.send(:leap_year?, 2000), "2000 is a leap year"
14
14
  refute enum.send(:leap_year?, 1998), "1998 is not a leap year"
15
15
  refute enum.send(:leap_year?, 1900), "1900 is not a leap year"
16
16
  end
17
-
18
-
19
-
17
+
18
+
19
+
20
20
  end
@@ -3,8 +3,8 @@ require "test_helper"
3
3
 
4
4
  class MonthlyEnumeratorTest < ActiveSupport::TestCase
5
5
  include Hiccup
6
-
7
-
6
+
7
+
8
8
  context "with a complex schedule" do
9
9
  setup do
10
10
  @schedule = Schedule.new({
@@ -20,7 +20,7 @@ class MonthlyEnumeratorTest < ActiveSupport::TestCase
20
20
  start_date: Date.new(2005, 1, 8)
21
21
  })
22
22
  end
23
-
23
+
24
24
  context "when enumerating backward" do
25
25
  should "return the most-recent date prior to the start_date, NOT the earliest date in the month" do
26
26
  # Start with a date in the middle of the month
@@ -32,8 +32,8 @@ class MonthlyEnumeratorTest < ActiveSupport::TestCase
32
32
  end
33
33
  end
34
34
  end
35
-
36
-
35
+
36
+
37
37
  context "with a schedule that skips" do
38
38
  setup do
39
39
  @schedule = Schedule.new(
@@ -42,7 +42,7 @@ class MonthlyEnumeratorTest < ActiveSupport::TestCase
42
42
  monthly_pattern: [[1, "Thursday"]],
43
43
  start_date: Date.new(2015, 1, 1))
44
44
  end
45
-
45
+
46
46
  context "when enumerating from a date in a skipped month" do
47
47
  should "skip months from the schedule's start date not from the offset" do
48
48
  date = Date.new(2015, 2, 1)
@@ -50,7 +50,7 @@ class MonthlyEnumeratorTest < ActiveSupport::TestCase
50
50
  assert_equal Date.new(2015, 3, 5), enumerator.next
51
51
  end
52
52
  end
53
-
53
+
54
54
  context "when enumerating forward from a date toward the end of a skipped month" do
55
55
  should "find the first date from the start of an unskipped month" do
56
56
  date = Date.new(2015, 4, 30)
@@ -58,7 +58,7 @@ class MonthlyEnumeratorTest < ActiveSupport::TestCase
58
58
  assert_equal Date.new(2015, 5, 7), enumerator.next
59
59
  end
60
60
  end
61
-
61
+
62
62
  context "when enumerating backward from a date toward the beginning of a skipped month" do
63
63
  should "find the first date from the end of an unskipped month" do
64
64
  date = Date.new(2015, 6, 1)
@@ -67,8 +67,8 @@ class MonthlyEnumeratorTest < ActiveSupport::TestCase
67
67
  end
68
68
  end
69
69
  end
70
-
71
-
70
+
71
+
72
72
  context "with an empty schedule" do
73
73
  setup do
74
74
  @schedule = Schedule.new(
@@ -77,13 +77,13 @@ class MonthlyEnumeratorTest < ActiveSupport::TestCase
77
77
  monthly_pattern: [],
78
78
  start_date: Date.new(2015, 1, 1))
79
79
  end
80
-
80
+
81
81
  should "always return nil" do
82
82
  date = Date.new(2015, 2, 1)
83
83
  enumerator = @schedule.enumerator.new(@schedule, date)
84
84
  assert_equal nil, enumerator.next
85
85
  end
86
86
  end
87
-
88
-
87
+
88
+
89
89
  end
@@ -3,8 +3,8 @@ require "benchmark"
3
3
 
4
4
  class PerformanceTest < ActiveSupport::TestCase
5
5
  include Hiccup
6
-
7
-
6
+
7
+
8
8
  { 100 => 50,
9
9
  500 => 50,
10
10
  1000 => 50 }.each do |number, expected_duration|
@@ -16,11 +16,11 @@ class PerformanceTest < ActiveSupport::TestCase
16
16
  assert duration <= expected_duration, "It took %.2fms" % duration
17
17
  end
18
18
  end
19
-
20
-
19
+
20
+
21
21
  # Inferring 500 dates still takes 10 seconds.
22
22
  # It spends 7.3 of those seconds predicting dates,
23
- # 6.9 of those predicting monthly or weekly dates.
23
+ # 6.9 of those predicting monthly or weekly dates.
24
24
  { 10 => 0.1.seconds,
25
25
  50 => 0.5.seconds,
26
26
  100 => 1.0.seconds }.each do |number, expected_duration|
@@ -30,6 +30,6 @@ class PerformanceTest < ActiveSupport::TestCase
30
30
  assert duration <= expected_duration, "It took %.2f seconds" % duration
31
31
  end
32
32
  end
33
-
34
-
33
+
34
+
35
35
  end
@@ -115,4 +115,4 @@ private
115
115
 
116
116
 
117
117
 
118
- end
118
+ end
@@ -3,71 +3,71 @@ require "test_helper"
3
3
 
4
4
  class WeeklyEnumeratorTest < ActiveSupport::TestCase
5
5
  include Hiccup
6
-
7
-
8
-
6
+
7
+
8
+
9
9
  test "should generate a cycle of [7] for something that occurs every week on one day" do
10
10
  assert_equal [7], cycle_for(
11
11
  :start_date => Date.new(2013, 9, 23),
12
12
  :weekly_pattern => ["Monday"])
13
13
  end
14
-
14
+
15
15
  test "should generate a cycle of [21] for something that occurs every _third_ week on one day" do
16
16
  assert_equal [21], cycle_for(
17
17
  :start_date => Date.new(2013, 9, 23),
18
18
  :weekly_pattern => ["Monday"],
19
19
  :skip => 3)
20
20
  end
21
-
22
-
23
-
21
+
22
+
23
+
24
24
  test "should generate a cycle of [6, 8] for something that occurs every other Saturday and Sunday when the start date is a Sunday" do
25
25
  assert_equal [6, 8], cycle_for(
26
26
  :start_date => Date.new(2013, 9, 22),
27
27
  :weekly_pattern => ["Saturday", "Sunday"],
28
28
  :skip => 2)
29
29
  end
30
-
30
+
31
31
  test "should generate a cycle of [8, 6] for something that occurs every other Saturday and Sunday when the start date is a Saturday" do
32
32
  assert_equal [8, 6], cycle_for(
33
33
  :start_date => Date.new(2013, 9, 28),
34
34
  :weekly_pattern => ["Saturday", "Sunday"],
35
35
  :skip => 2)
36
36
  end
37
-
38
-
39
-
37
+
38
+
39
+
40
40
  test "should generate a cycle of [2, 2, 10] for something that occurs every other Monday, Wednesday, Friday when the start date is a Monday" do
41
41
  assert_equal [2, 2, 10], cycle_for(
42
42
  :start_date => Date.new(2013, 9, 23),
43
43
  :weekly_pattern => ["Monday", "Wednesday", "Friday"],
44
44
  :skip => 2)
45
45
  end
46
-
46
+
47
47
  test "should generate a cycle of [2, 10, 2] for something that occurs every other Monday, Wednesday, Friday when the start date is a Wednesday" do
48
48
  assert_equal [2, 10, 2], cycle_for(
49
49
  :start_date => Date.new(2013, 9, 25),
50
50
  :weekly_pattern => ["Monday", "Wednesday", "Friday"],
51
51
  :skip => 2)
52
52
  end
53
-
53
+
54
54
  test "should generate a cycle of [10, 2, 2] for something that occurs every other Monday, Wednesday, Friday when the start date is a Friday" do
55
55
  assert_equal [10, 2, 2], cycle_for(
56
56
  :start_date => Date.new(2013, 9, 27),
57
57
  :weekly_pattern => ["Monday", "Wednesday", "Friday"],
58
58
  :skip => 2)
59
59
  end
60
-
61
-
62
-
60
+
61
+
62
+
63
63
  test "should generate a cycle of [2, 5] for something that occurs every Tuesday and Thursday when the start date is a Friday" do
64
64
  assert_equal [2, 5], cycle_for(
65
65
  :start_date => Date.new(2013, 9, 27),
66
66
  :weekly_pattern => ["Tuesday", "Thursday"])
67
67
  end
68
-
69
-
70
-
68
+
69
+
70
+
71
71
  context "#position_of" do
72
72
  setup do
73
73
  @schedule = Schedule.new(
@@ -76,11 +76,11 @@ class WeeklyEnumeratorTest < ActiveSupport::TestCase
76
76
  :weekly_pattern => ["Tuesday", "Thursday", "Friday"],
77
77
  :skip => 2)
78
78
  end
79
-
79
+
80
80
  should "be a sane test" do
81
81
  assert_equal [1, 11, 2], cycle_for(@schedule)
82
82
  end
83
-
83
+
84
84
  should "find the correct position for the given date" do
85
85
  assert_equal 0, position_of(@schedule, 2013, 9, 26)
86
86
  assert_equal 1, position_of(@schedule, 2013, 9, 27)
@@ -90,9 +90,9 @@ class WeeklyEnumeratorTest < ActiveSupport::TestCase
90
90
  assert_equal 2, position_of(@schedule, 2013, 10, 22)
91
91
  end
92
92
  end
93
-
94
-
95
-
93
+
94
+
95
+
96
96
  context "with a complex schedule" do
97
97
  setup do
98
98
  @schedule = Schedule.new(
@@ -100,15 +100,15 @@ class WeeklyEnumeratorTest < ActiveSupport::TestCase
100
100
  :start_date => Date.new(2013, 9, 26), # Thursday
101
101
  :weekly_pattern => ["Tuesday", "Thursday", "Friday"])
102
102
  end
103
-
103
+
104
104
  should "pick the right date when enumerating backward" do
105
105
  enumerator = @schedule.enumerator.new(@schedule, Date.new(2013, 10, 16)) # Wednesday!
106
106
  assert_equal Date.new(2013, 10, 15), enumerator.prev
107
107
  end
108
108
  end
109
-
110
-
111
-
109
+
110
+
111
+
112
112
  context "Given an invalid schedule with no weekly pattern, it" do
113
113
  setup do
114
114
  @schedule = Schedule.new(
@@ -116,42 +116,42 @@ class WeeklyEnumeratorTest < ActiveSupport::TestCase
116
116
  :start_date => Date.new(2013, 9, 26),
117
117
  :weekly_pattern => [])
118
118
  end
119
-
119
+
120
120
  should "return nil for prev rather than raising an exception" do
121
121
  enumerator = @schedule.enumerator.new(@schedule, Date.today)
122
122
  assert_equal nil, enumerator.prev
123
123
  end
124
-
124
+
125
125
  should "return nil for next rather than raising an exception" do
126
126
  enumerator = @schedule.enumerator.new(@schedule, Date.today)
127
127
  assert_equal nil, enumerator.next
128
128
  end
129
129
  end
130
-
131
-
132
-
130
+
131
+
132
+
133
133
  private
134
-
134
+
135
135
  def cycle_for(options={})
136
136
  schedule = build_schedule(options)
137
137
  enumerator = schedule.enumerator.new(schedule, Date.today)
138
138
  enumerator.send :calculate_cycle, schedule
139
139
  end
140
-
140
+
141
141
  def position_of(schedule, *args)
142
142
  date = build_date(*args)
143
143
  enumerator = schedule.enumerator.new(schedule, date)
144
144
  enumerator.send :position_of, date
145
145
  end
146
-
146
+
147
147
  def build_schedule(options={})
148
148
  return options if options.is_a? Schedule
149
149
  Schedule.new(options.merge(:kind => :weekly))
150
150
  end
151
-
151
+
152
152
  def build_date(*args)
153
153
  return Date.new(*args) if args.length == 3
154
154
  args.first
155
155
  end
156
-
156
+
157
157
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hiccup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.14
4
+ version: 0.5.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Lail
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-06 00:00:00.000000000 Z
11
+ date: 2015-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -157,6 +157,7 @@ files:
157
157
  - lib/hiccup/enumerable/never_enumerator.rb
158
158
  - lib/hiccup/enumerable/schedule_enumerator.rb
159
159
  - lib/hiccup/enumerable/weekly_enumerator.rb
160
+ - lib/hiccup/errors.rb
160
161
  - lib/hiccup/humanizable.rb
161
162
  - lib/hiccup/inferable.rb
162
163
  - lib/hiccup/inferable/dates_enumerator.rb
@@ -199,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
199
200
  version: '0'
200
201
  requirements: []
201
202
  rubyforge_project: hiccup
202
- rubygems_version: 2.2.2
203
+ rubygems_version: 2.4.8
203
204
  signing_key:
204
205
  specification_version: 4
205
206
  summary: A library for working with things that recur