ice_cube 0.5.3 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ice_cube/rule_occurrence.rb +7 -8
- data/lib/ice_cube/schedule.rb +2 -2
- data/lib/ice_cube/validation.rb +12 -9
- data/lib/ice_cube/validations/day.rb +3 -3
- data/lib/ice_cube/validations/day_of_month.rb +2 -2
- data/lib/ice_cube/validations/day_of_week.rb +2 -2
- data/lib/ice_cube/validations/day_of_year.rb +2 -2
- data/lib/ice_cube/validations/hour_of_day.rb +2 -2
- data/lib/ice_cube/validations/minute_of_hour.rb +2 -2
- data/lib/ice_cube/validations/month_of_year.rb +3 -3
- data/lib/ice_cube/validations/second_of_minute.rb +2 -2
- data/lib/ice_cube/version.rb +1 -1
- metadata +4 -4
@@ -1,13 +1,12 @@
|
|
1
1
|
module IceCube
|
2
2
|
|
3
3
|
class RuleOccurrence
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
4
|
+
|
5
|
+
# allow to be compared to dates (awesome but not used anymore)
|
6
|
+
# include Comparable
|
7
|
+
# def <=>(other)
|
8
|
+
# to_time <=> other
|
9
|
+
# end
|
11
10
|
|
12
11
|
def to_time
|
13
12
|
@date
|
@@ -45,8 +44,8 @@ module IceCube
|
|
45
44
|
begin
|
46
45
|
return nil if @end_time && date > @end_time
|
47
46
|
return nil if @rule.until_date && date > @rule.until_date # until check
|
48
|
-
next unless @rule.in_interval?(date, @start_date)
|
49
47
|
return nil if yield(date)
|
48
|
+
next unless @rule.in_interval?(date, @start_date)
|
50
49
|
return RuleOccurrence.new(@rule, @start_date, @end_time, date, @index + 1)
|
51
50
|
end while date = @rule.next_suggestion(date)
|
52
51
|
end
|
data/lib/ice_cube/schedule.rb
CHANGED
@@ -165,7 +165,7 @@ module IceCube
|
|
165
165
|
# adjust to the propert end date
|
166
166
|
end_time = @end_time if @end_time && @end_time < end_time
|
167
167
|
# collect the occurrences
|
168
|
-
include_dates = SortedSet.new(@rdates)
|
168
|
+
include_dates, exclude_dates = SortedSet.new(@rdates), Set.new(@exdates)
|
169
169
|
@rrule_occurrence_heads.each do |rrule_occurrence_head|
|
170
170
|
include_dates.merge(rrule_occurrence_head.between(begin_time, end_time))
|
171
171
|
end
|
@@ -173,7 +173,7 @@ module IceCube
|
|
173
173
|
exclude_dates.merge(exrule_occurrence_head.between(begin_time, end_time))
|
174
174
|
end
|
175
175
|
# reject all of the ones outside of the range
|
176
|
-
include_dates.reject! { |date|
|
176
|
+
include_dates.reject! { |date| exclude_dates.include?(date) || date < begin_time || date > end_time }
|
177
177
|
include_dates.to_a
|
178
178
|
end
|
179
179
|
|
data/lib/ice_cube/validation.rb
CHANGED
@@ -3,14 +3,15 @@ module IceCube
|
|
3
3
|
class Validation
|
4
4
|
|
5
5
|
NUMBER_SUFFIX = ['th', 'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th']
|
6
|
-
|
7
|
-
|
6
|
+
SPECIAL_SUFFIX = { 11 => 'th', 12 => 'th', 13 => 'th', 14 => 'th' }
|
7
|
+
|
8
|
+
def self.adjust(goal, date)
|
8
9
|
return goal if goal.utc_offset == date.utc_offset
|
9
10
|
goal - goal.utc_offset + date.utc_offset
|
10
11
|
end
|
11
12
|
|
12
13
|
# influences by ActiveSupport's to_sentence
|
13
|
-
def sentence(array)
|
14
|
+
def self.sentence(array)
|
14
15
|
case array.length
|
15
16
|
when 0 ; ''
|
16
17
|
when 1 ; array[0].to_s
|
@@ -19,23 +20,25 @@ module IceCube
|
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
22
|
-
def nice_numbers(array)
|
23
|
+
def self.nice_numbers(array)
|
23
24
|
array.sort!
|
24
|
-
sentence array.map { |d| nice_number(d) }
|
25
|
+
self.sentence array.map { |d| nice_number(d) }
|
25
26
|
end
|
26
27
|
|
27
28
|
private
|
28
29
|
|
29
|
-
def nice_number(number)
|
30
|
+
def self.nice_number(number)
|
30
31
|
if number == -1
|
31
32
|
'last'
|
32
33
|
elsif number < -1
|
33
|
-
number
|
34
|
+
suffix = SPECIAL_SUFFIX.include?(number) ? SPECIAL_SUFFIX[number] : NUMBER_SUFFIX[number.abs % 10]
|
35
|
+
number.abs.to_s << suffix << ' to last'
|
34
36
|
else
|
35
|
-
number
|
37
|
+
suffix = SPECIAL_SUFFIX.include?(number) ? SPECIAL_SUFFIX[number] : NUMBER_SUFFIX[number.abs % 10]
|
38
|
+
number.to_s << suffix
|
36
39
|
end
|
37
40
|
end
|
38
41
|
|
39
42
|
end
|
40
43
|
|
41
|
-
end
|
44
|
+
end
|
@@ -21,12 +21,12 @@ module IceCube
|
|
21
21
|
days.compact!
|
22
22
|
# go to the closest distance away, the start of that day
|
23
23
|
goal = date + days.min * IceCube::ONE_DAY
|
24
|
-
adjust(goal, date)
|
24
|
+
self.class.adjust(goal, date)
|
25
25
|
end
|
26
26
|
|
27
27
|
def to_s
|
28
28
|
days_dup = (@days - @rule.validations[:day_of_week].keys if @rule.validations[:day_of_week]) || @days # don't list twice
|
29
|
-
'on ' << sentence(days_dup.map { |d| Date::DAYNAMES[d] + 's' }) unless days_dup.empty?
|
29
|
+
'on ' << self.class.sentence(days_dup.map { |d| Date::DAYNAMES[d] + 's' }) unless days_dup.empty?
|
30
30
|
end
|
31
31
|
|
32
32
|
def to_ical
|
@@ -36,4 +36,4 @@ module IceCube
|
|
36
36
|
|
37
37
|
end
|
38
38
|
|
39
|
-
end
|
39
|
+
end
|
@@ -34,11 +34,11 @@ module IceCube
|
|
34
34
|
return nil if distances.empty?
|
35
35
|
# return the start of the proper day
|
36
36
|
goal = date + distances.min * IceCube::ONE_DAY
|
37
|
-
adjust(goal, date)
|
37
|
+
self.class.adjust(goal, date)
|
38
38
|
end
|
39
39
|
|
40
40
|
def to_s
|
41
|
-
'on the ' << nice_numbers(@days_of_month) << (@days_of_month.size == 1 ? ' day' : ' days') << ' of the month' unless @days_of_month.empty?
|
41
|
+
'on the ' << self.class.nice_numbers(@days_of_month) << (@days_of_month.size == 1 ? ' day' : ' days') << ' of the month' unless @days_of_month.empty?
|
42
42
|
end
|
43
43
|
|
44
44
|
def to_ical
|
@@ -26,7 +26,7 @@ module IceCube
|
|
26
26
|
return nil if !@days_of_week || @days_of_week.empty?
|
27
27
|
goal = date
|
28
28
|
while goal += IceCube::ONE_DAY
|
29
|
-
return adjust(goal, date) if validate(goal)
|
29
|
+
return self.class.adjust(goal, date) if validate(goal)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -34,7 +34,7 @@ module IceCube
|
|
34
34
|
representation = ''
|
35
35
|
representation << 'on the '
|
36
36
|
representation << @days_of_week.map do |day, occ|
|
37
|
-
nice_numbers(occ) << ' ' << Date::DAYNAMES[day] << (occ.size != 1 ? 's' : '') unless @days_of_week.empty?
|
37
|
+
self.class.nice_numbers(occ) << ' ' << Date::DAYNAMES[day] << (occ.size != 1 ? 's' : '') unless @days_of_week.empty?
|
38
38
|
end.join(' and the ')
|
39
39
|
representation
|
40
40
|
end
|
@@ -33,11 +33,11 @@ module IceCube
|
|
33
33
|
return nil if distances.empty?
|
34
34
|
# return the start of the proper day
|
35
35
|
goal = date + distances.min * IceCube::ONE_DAY
|
36
|
-
adjust(goal, date)
|
36
|
+
self.class.adjust(goal, date)
|
37
37
|
end
|
38
38
|
|
39
39
|
def to_s
|
40
|
-
'on the ' << nice_numbers(@days_of_year) << (@days_of_year.size == 1 ? ' day' : ' days') << ' of the year' unless @days_of_year.empty?
|
40
|
+
'on the ' << self.class.nice_numbers(@days_of_year) << (@days_of_year.size == 1 ? ' day' : ' days') << ' of the year' unless @days_of_year.empty?
|
41
41
|
end
|
42
42
|
|
43
43
|
def to_ical
|
@@ -22,11 +22,11 @@ module IceCube
|
|
22
22
|
# go to the closest distance away, the start of that hour
|
23
23
|
closest_hour = hours.min
|
24
24
|
goal = date + IceCube::ONE_HOUR * closest_hour
|
25
|
-
adjust(goal, date)
|
25
|
+
self.class.adjust(goal, date)
|
26
26
|
end
|
27
27
|
|
28
28
|
def to_s
|
29
|
-
'on the ' << nice_numbers(@hours_of_day) << (@hours_of_day.size == 1 ? ' hour' : ' hours') << ' of the day' unless @hours_of_day.empty?
|
29
|
+
'on the ' << self.class.nice_numbers(@hours_of_day) << (@hours_of_day.size == 1 ? ' hour' : ' hours') << ' of the day' unless @hours_of_day.empty?
|
30
30
|
end
|
31
31
|
|
32
32
|
def to_ical
|
@@ -22,11 +22,11 @@ module IceCube
|
|
22
22
|
# go to the closest distance away, the beginning of that minute
|
23
23
|
closest_minute = minutes.min
|
24
24
|
goal = date + closest_minute * IceCube::ONE_MINUTE
|
25
|
-
adjust(goal, date)
|
25
|
+
self.class.adjust(goal, date)
|
26
26
|
end
|
27
27
|
|
28
28
|
def to_s
|
29
|
-
'on the ' << nice_numbers(@minutes_of_hour) << (@minutes_of_hour.size == 1 ? ' minute' : ' minutes') << ' of the hour' unless @minutes_of_hour.empty?
|
29
|
+
'on the ' << self.class.nice_numbers(@minutes_of_hour) << (@minutes_of_hour.size == 1 ? ' minute' : ' minutes') << ' of the hour' unless @minutes_of_hour.empty?
|
30
30
|
end
|
31
31
|
|
32
32
|
def to_ical
|
@@ -22,11 +22,11 @@ module IceCube
|
|
22
22
|
# go to the closest distance away
|
23
23
|
goal = date
|
24
24
|
months.min.times { goal += TimeUtil.days_in_month(goal) * IceCube::ONE_DAY }
|
25
|
-
adjust(goal, date)
|
25
|
+
self.class.adjust(goal, date)
|
26
26
|
end
|
27
27
|
|
28
28
|
def to_s
|
29
|
-
'in ' << @months_of_year.map { |m| Date::MONTHNAMES[m] }
|
29
|
+
'in ' << self.class.sentence(@months_of_year.map { |m| Date::MONTHNAMES[m] }) unless @months_of_year.empty?
|
30
30
|
end
|
31
31
|
|
32
32
|
def to_ical
|
@@ -35,4 +35,4 @@ module IceCube
|
|
35
35
|
|
36
36
|
end
|
37
37
|
|
38
|
-
end
|
38
|
+
end
|
@@ -22,11 +22,11 @@ module IceCube
|
|
22
22
|
# go to the closest distance away
|
23
23
|
closest_second = seconds.min
|
24
24
|
goal = date + closest_second
|
25
|
-
adjust(goal, date)
|
25
|
+
self.class.adjust(goal, date)
|
26
26
|
end
|
27
27
|
|
28
28
|
def to_s
|
29
|
-
'on the ' << nice_numbers(@seconds_of_minute) << (@seconds_of_minute.size == 1 ? ' second' : ' seconds') << ' of the minute' unless @seconds_of_minute.empty?
|
29
|
+
'on the ' << self.class.nice_numbers(@seconds_of_minute) << (@seconds_of_minute.size == 1 ? ' second' : ' seconds') << ' of the minute' unless @seconds_of_minute.empty?
|
30
30
|
end
|
31
31
|
|
32
32
|
def to_ical
|
data/lib/ice_cube/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ice_cube
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.5.
|
9
|
+
- 4
|
10
|
+
version: 0.5.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- John Crepezzi
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-27 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|