hiccup 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7d10125513beb88e0c6c96db75cc928db898ad2f
4
- data.tar.gz: fc07262a4ea66ef9d964f69e5a9d69971c2ee557
3
+ metadata.gz: 86859b5552e51f3c4bb91170033f32fb4cdf2c4e
4
+ data.tar.gz: 8987c7d7ae39b2c83dc109ac7f409f3f22d5d7dc
5
5
  SHA512:
6
- metadata.gz: 72ab32b2d1fbaacf611d09063be2f223f322a4de8af2cb83c950a52b723d2ebdc6b6ae31281459d319d063e1a65d84dabd36befd07245909e9d694cf2c1718a3
7
- data.tar.gz: bd3b19597a7ff8444ef1a51ac294e5bf1b56ef9d8d4473419d799adb87662638bd602939b8026a2fd0674592d5e3a21648775f57372921144f0580494df9d376
6
+ metadata.gz: 68dc0bbf57fba21d13aae5c6786ff679761f690fbc1e6ed05c382d698150e59d4501317f74d84e21fdb8825ef47fed0d362215b4d628d9fcf85f9f15905ebc1e
7
+ data.tar.gz: eb01df9e219e4a0a38fdd79fd7e5c63fae0a8def9ca1c5b0db745a9e562615566154aa03719178ea847a8345ae8586c8b507e943cc326ab90bd8bdf97ac99272
@@ -17,9 +17,6 @@ module Hiccup
17
17
 
18
18
 
19
19
  def occurrences_between(earlier_date, later_date)
20
- return [] if ends? && earlier_date > end_date
21
- return [] if later_date < start_date
22
-
23
20
  occurrences = []
24
21
  enum = enumerator.new(self, earlier_date)
25
22
  while (occurrence = enum.next) && (occurrence <= later_date)
@@ -31,7 +28,6 @@ module Hiccup
31
28
 
32
29
 
33
30
  def first_occurrence_on_or_after(date)
34
- return nil if ends? && date > end_date
35
31
  enumerator.new(self, date).next
36
32
  end
37
33
 
@@ -43,7 +39,6 @@ module Hiccup
43
39
 
44
40
 
45
41
  def first_occurrence_on_or_before(date)
46
- return nil if date < start_date
47
42
  enumerator.new(self, date).prev
48
43
  end
49
44
 
@@ -67,8 +62,6 @@ module Hiccup
67
62
  end
68
63
 
69
64
  def n_occurrences_on_or_before(limit, date)
70
- return [] if date < start_date
71
-
72
65
  occurrences = []
73
66
  enum = enumerator.new(self, date)
74
67
  while (occurrence = enum.prev) && occurrences.length < limit
@@ -88,8 +81,6 @@ module Hiccup
88
81
  end
89
82
 
90
83
  def n_occurrences_on_or_after(limit, date)
91
- return [] if ends? and date > end_date
92
-
93
84
  occurrences = []
94
85
  enum = enumerator.new(self, date)
95
86
  while (occurrence = enum.next) && occurrences.length < limit
@@ -7,40 +7,42 @@ module Hiccup
7
7
  def initialize(*args)
8
8
  super
9
9
  @month, @day = start_date.month, start_date.day
10
- @february_29 = month == 2 and day == 29
10
+
11
+ if month == 2 and day == 29
12
+ def self.current_date
13
+ Date.new(year, 2, leap_year?(year) ? 29 : 28)
14
+ end
15
+ end
11
16
  end
12
17
 
13
- protected
14
-
18
+ attr_reader :month, :day
15
19
 
16
- attr_reader :month, :day, :year
20
+ protected
17
21
 
18
- def february_29?
19
- @february_29
20
- end
22
+ attr_reader :year
21
23
 
22
24
 
23
25
 
24
26
  def advance!
25
27
  @year += skip
26
- to_date!
28
+ current_date
27
29
  end
28
30
 
29
31
  def rewind!
30
32
  @year -= skip
31
- to_date!
33
+ current_date
32
34
  end
33
35
 
34
36
 
35
37
 
36
38
  def first_occurrence_on_or_after(date)
37
39
  @year = date.year
38
- @year += skip if (date.month > month) or (date.month == month and date.day > day)
40
+ @year += 1 if (date.month > month) or (date.month == month and date.day > day)
39
41
 
40
42
  remainder = (@year - start_date.year) % skip
41
43
  @year += (skip - remainder) if remainder > 0
42
44
 
43
- to_date!
45
+ current_date
44
46
  end
45
47
 
46
48
  def first_occurrence_on_or_before(date)
@@ -50,13 +52,12 @@ module Hiccup
50
52
  remainder = (@year - start_date.year) % skip
51
53
  @year -= remainder if remainder > 0
52
54
 
53
- to_date!
55
+ current_date
54
56
  end
55
57
 
56
58
 
57
59
 
58
- def to_date!
59
- return Date.new(year, month, 28) if february_29? and !leap_year?(year)
60
+ def current_date
60
61
  Date.new(year, month, day)
61
62
  end
62
63
 
@@ -5,12 +5,21 @@ module Hiccup
5
5
  class NeverEnumerator < ScheduleEnumerator
6
6
 
7
7
 
8
+ def next
9
+ @cursor = @cursor ? nil : first_occurrence_on_or_after(seed_date)
10
+ end
11
+
12
+ def prev
13
+ @cursor = @cursor ? nil : first_occurrence_on_or_before(seed_date)
14
+ end
15
+
16
+
8
17
  def first_occurrence_on_or_after(date)
9
- date if date == start_date
18
+ start_date if date <= start_date
10
19
  end
11
20
 
12
21
  def first_occurrence_on_or_before(date)
13
- date
22
+ start_date unless date < start_date
14
23
  end
15
24
 
16
25
 
@@ -1,4 +1,3 @@
1
-
2
1
  module Hiccup
3
2
  module Enumerable
4
3
  class ScheduleEnumerator
@@ -19,8 +18,6 @@ module Hiccup
19
18
  @ends = schedule.ends?
20
19
  @seed_date = seed_date
21
20
  @seed_date = seed_date.to_date if seed_date.respond_to?(:to_date)
22
- @seed_date = start_date if (seed_date < start_date)
23
- @seed_date = end_date if (ends? && seed_date > end_date)
24
21
  @cursor = nil
25
22
  end
26
23
 
@@ -29,13 +26,13 @@ module Hiccup
29
26
 
30
27
 
31
28
  def next
32
- @cursor = started? ? advance! : first_occurrence_on_or_after(seed_date)
29
+ @cursor = started? ? advance! : first_occurrence_on_or_after(seed_start_date)
33
30
  return nil if ends? && @cursor > end_date
34
31
  @cursor
35
32
  end
36
33
 
37
34
  def prev
38
- @cursor = started? ? rewind! : first_occurrence_on_or_before(seed_date)
35
+ @cursor = started? ? rewind! : first_occurrence_on_or_before(seed_end_date)
39
36
  return nil if @cursor < start_date
40
37
  @cursor
41
38
  end
@@ -68,6 +65,18 @@ module Hiccup
68
65
 
69
66
 
70
67
 
68
+ def seed_start_date
69
+ return start_date if (seed_date < start_date)
70
+ seed_date
71
+ end
72
+
73
+ def seed_end_date
74
+ return end_date if (ends? && seed_date > end_date)
75
+ seed_date
76
+ end
77
+
78
+
79
+
71
80
  # These two methods DO assume that
72
81
  # date is predicted by the given schedule
73
82
  # Subclasses can probably supply more
@@ -1,3 +1,3 @@
1
1
  module Hiccup
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  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.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Lail
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-28 00:00:00.000000000 Z
11
+ date: 2013-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -171,7 +171,7 @@ files:
171
171
  - test/performance_test.rb
172
172
  - test/test_helper.rb
173
173
  - test/validatable_test.rb
174
- - test/weekly_enumerator_test_test.rb
174
+ - test/weekly_enumerator_test.rb
175
175
  homepage: http://boblail.github.com/hiccup/
176
176
  licenses: []
177
177
  metadata: {}
@@ -206,4 +206,4 @@ test_files:
206
206
  - test/performance_test.rb
207
207
  - test/test_helper.rb
208
208
  - test/validatable_test.rb
209
- - test/weekly_enumerator_test_test.rb
209
+ - test/weekly_enumerator_test.rb