ice_cube 0.6.10 → 0.7.0

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.
Files changed (43) hide show
  1. data/lib/ice_cube/builders/hash_builder.rb +27 -0
  2. data/lib/ice_cube/builders/ical_builder.rb +59 -0
  3. data/lib/ice_cube/builders/string_builder.rb +74 -0
  4. data/lib/ice_cube/errors/count_exceeded.rb +7 -0
  5. data/lib/ice_cube/errors/until_exceeded.rb +7 -0
  6. data/lib/ice_cube/rule.rb +86 -140
  7. data/lib/ice_cube/rules/daily_rule.rb +5 -27
  8. data/lib/ice_cube/rules/hourly_rule.rb +6 -26
  9. data/lib/ice_cube/rules/minutely_rule.rb +5 -25
  10. data/lib/ice_cube/rules/monthly_rule.rb +6 -30
  11. data/lib/ice_cube/rules/secondly_rule.rb +5 -26
  12. data/lib/ice_cube/rules/weekly_rule.rb +5 -36
  13. data/lib/ice_cube/rules/yearly_rule.rb +8 -34
  14. data/lib/ice_cube/schedule.rb +262 -189
  15. data/lib/ice_cube/single_occurrence_rule.rb +28 -0
  16. data/lib/ice_cube/time_util.rb +202 -76
  17. data/lib/ice_cube/validated_rule.rb +107 -0
  18. data/lib/ice_cube/validations/count.rb +56 -0
  19. data/lib/ice_cube/validations/daily_interval.rb +51 -0
  20. data/lib/ice_cube/validations/day.rb +45 -29
  21. data/lib/ice_cube/validations/day_of_month.rb +45 -43
  22. data/lib/ice_cube/validations/day_of_week.rb +59 -41
  23. data/lib/ice_cube/validations/day_of_year.rb +49 -43
  24. data/lib/ice_cube/validations/hour_of_day.rb +43 -29
  25. data/lib/ice_cube/validations/hourly_interval.rb +50 -0
  26. data/lib/ice_cube/validations/lock.rb +47 -0
  27. data/lib/ice_cube/validations/minute_of_hour.rb +43 -30
  28. data/lib/ice_cube/validations/minutely_interval.rb +50 -0
  29. data/lib/ice_cube/validations/month_of_year.rb +40 -29
  30. data/lib/ice_cube/validations/monthly_interval.rb +47 -0
  31. data/lib/ice_cube/validations/schedule_lock.rb +41 -0
  32. data/lib/ice_cube/validations/second_of_minute.rb +40 -29
  33. data/lib/ice_cube/validations/secondly_interval.rb +50 -0
  34. data/lib/ice_cube/validations/until.rb +49 -0
  35. data/lib/ice_cube/validations/weekly_interval.rb +50 -0
  36. data/lib/ice_cube/validations/yearly_interval.rb +45 -0
  37. data/lib/ice_cube/version.rb +2 -2
  38. data/lib/ice_cube.rb +63 -37
  39. data/spec/spec_helper.rb +13 -0
  40. metadata +47 -8
  41. data/lib/ice_cube/rule_occurrence.rb +0 -100
  42. data/lib/ice_cube/validation.rb +0 -44
  43. data/lib/ice_cube/validation_types.rb +0 -137
@@ -1,38 +1,49 @@
1
1
  module IceCube
2
2
 
3
- class SecondOfMinuteValidation < Validation
4
-
5
- def initialize(rule)
6
- @seconds_of_minute = rule.validations[:second_of_minute]
7
- end
8
-
9
- def validate(date)
10
- return true if !@seconds_of_minute || @seconds_of_minute.empty?
11
- @seconds_of_minute.include?(date.sec)
12
- end
13
-
14
- def closest(date)
15
- return nil if !@seconds_of_minute || @seconds_of_minute.empty?
16
- # turn seconds into seconds of minute
17
- # second >= 60 should fall into the next minute
18
- seconds = @seconds_of_minute.map do |s|
19
- s > date.sec ? s - date.sec : 60 - date.sec + s
3
+ module Validations::SecondOfMinute
4
+
5
+ def second_of_minute(*seconds)
6
+ seconds.each do |second|
7
+ validations_for(:second_of_minute) << Validation.new(second)
20
8
  end
21
- seconds.compact!
22
- # go to the closest distance away
23
- closest_second = seconds.min
24
- goal = date + closest_second
25
- self.class.adjust(goal, date)
9
+ clobber_base_validations :sec
10
+ self
26
11
  end
27
12
 
28
- def to_s
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
- end
13
+ class Validation
14
+
15
+ include Validations::Lock
16
+
17
+ StringBuilder.register_formatter(:second_of_minute) do |segments|
18
+ str = "on the #{StringBuilder.sentence(segments)} "
19
+ str << (segments.size == 1 ? 'second of the minute' : 'seconds of the minute')
20
+ end
21
+
22
+ attr_reader :second
23
+ alias :value :second
24
+
25
+ def initialize(second)
26
+ @second = second
27
+ end
28
+
29
+ def type
30
+ :sec
31
+ end
32
+
33
+ def build_s(builder)
34
+ builder.piece(:second_of_minute) << StringBuilder.nice_number(second)
35
+ end
36
+
37
+ def build_hash(builder)
38
+ builder.validations_array(:second_of_minute) << second
39
+ end
40
+
41
+ def build_ical(builder)
42
+ builder['BYSECOND'] << second
43
+ end
31
44
 
32
- def to_ical
33
- 'BYSECOND=' << @seconds_of_minute.join(',') unless @seconds_of_minute.empty?
34
45
  end
35
-
46
+
36
47
  end
37
-
48
+
38
49
  end
@@ -0,0 +1,50 @@
1
+ module IceCube
2
+
3
+ module Validations::SecondlyInterval
4
+
5
+ def interval(interval)
6
+ validations_for(:interval) << Validation.new(interval)
7
+ clobber_base_validations(:sec)
8
+ self
9
+ end
10
+
11
+ class Validation
12
+
13
+ attr_reader :interval
14
+
15
+ def type
16
+ :sec
17
+ end
18
+
19
+ def dst_adjust?
20
+ false
21
+ end
22
+
23
+ def build_s(builder)
24
+ builder.base = interval == 1 ? 'Secondly' : "Every #{interval} seconds"
25
+ end
26
+
27
+ def build_ical(builder)
28
+ builder['FREQ'] << 'SECONDLY'
29
+ end
30
+
31
+ def build_hash(builder)
32
+ builder.validations[:interval] = interval
33
+ end
34
+
35
+ def initialize(interval)
36
+ @interval = interval
37
+ end
38
+
39
+ def validate(time, schedule)
40
+ seconds = time.to_i - schedule.start_time.to_i
41
+ unless seconds % interval == 0
42
+ interval - (seconds % interval)
43
+ end
44
+ end
45
+
46
+ end
47
+
48
+ end
49
+
50
+ end
@@ -0,0 +1,49 @@
1
+ module IceCube
2
+
3
+ module Validations::Until
4
+
5
+ # accessor
6
+ def until_time
7
+ @until
8
+ end
9
+ alias :until_date :until_time
10
+
11
+ def until(time)
12
+ @until = time
13
+ replace_validations_for(:until, [Validation.new(time)])
14
+ self
15
+ end
16
+
17
+ class Validation
18
+
19
+ attr_reader :time
20
+
21
+ def type
22
+ :dealbreaker
23
+ end
24
+
25
+ def initialize(time)
26
+ @time = time
27
+ end
28
+
29
+ def build_ical(builder)
30
+ builder['UNTIL'] << IcalBuilder.ical_utc_format(time)
31
+ end
32
+
33
+ def build_hash(builder)
34
+ builder[:until] = TimeUtil.serialize_time(time)
35
+ end
36
+
37
+ def build_s(builder)
38
+ builder.piece(:until) << "until #{time.strftime(TO_S_TIME_FORMAT)}"
39
+ end
40
+
41
+ def validate(t, schedule)
42
+ raise UntilExceeded if t > time
43
+ end
44
+
45
+ end
46
+
47
+ end
48
+
49
+ end
@@ -0,0 +1,50 @@
1
+ require 'date'
2
+
3
+ module IceCube
4
+
5
+ module Validations::WeeklyInterval
6
+
7
+ def interval(interval)
8
+ validations_for(:interval) << Validation.new(interval)
9
+ clobber_base_validations(:day)
10
+ end
11
+
12
+ class Validation
13
+
14
+ attr_reader :interval
15
+
16
+ def type
17
+ :day
18
+ end
19
+
20
+ def build_s(builder)
21
+ builder.base = interval == 1 ? 'Weekly' : "Every #{interval} weeks"
22
+ end
23
+
24
+ def build_ical(builder)
25
+ builder['FREQ'] << 'WEEKLY'
26
+ end
27
+
28
+ def build_hash(builder)
29
+ builder.validations[:interval] = interval
30
+ end
31
+
32
+ def initialize(interval)
33
+ @interval = interval
34
+ end
35
+
36
+ def validate(time, schedule)
37
+ date = Date.new(time.year, time.month, time.day)
38
+ st = schedule.start_time
39
+ start_date = Date.new(st.year, st.month, st.day)
40
+ weeks = ((date - date.wday) - (start_date - start_date.wday)) / 7
41
+ unless weeks % interval == 0
42
+ (interval - (weeks % interval)) * 7
43
+ end
44
+ end
45
+
46
+ end
47
+
48
+ end
49
+
50
+ end
@@ -0,0 +1,45 @@
1
+ module IceCube
2
+
3
+ module Validations::YearlyInterval
4
+
5
+ def interval(interval = 1)
6
+ validations_for(:interval) << Validation.new(interval)
7
+ clobber_base_validations(:year)
8
+ end
9
+
10
+ class Validation
11
+
12
+ attr_reader :interval
13
+
14
+ def type
15
+ :year
16
+ end
17
+
18
+ def build_s(builder)
19
+ builder.base = interval == 1 ? 'Yearly' : "Every #{interval} years"
20
+ end
21
+
22
+ def build_hash(builder)
23
+ builder.validations[:interval] = interval
24
+ end
25
+
26
+ def build_ical(builder)
27
+ builder['FREQ'] << 'YEARLY'
28
+ end
29
+
30
+ def initialize(interval)
31
+ @interval = interval
32
+ end
33
+
34
+ def validate(time, schedule)
35
+ years_to_start = time.year - schedule.start_time.year
36
+ unless years_to_start % interval == 0
37
+ interval - (years_to_start % interval)
38
+ end
39
+ end
40
+
41
+ end
42
+
43
+ end
44
+
45
+ end
@@ -1,5 +1,5 @@
1
1
  module IceCube
2
-
3
- VERSION = '0.6.10'
2
+
3
+ VERSION = '0.7.0'
4
4
 
5
5
  end
data/lib/ice_cube.rb CHANGED
@@ -1,48 +1,74 @@
1
- require 'yaml.rb'
2
- require 'set.rb'
3
1
  require 'date'
4
2
 
5
- require 'ice_cube/time_util'
6
-
7
- require 'ice_cube/validation'
8
- require 'ice_cube/validation_types'
9
- require 'ice_cube/rule'
10
- require 'ice_cube/schedule'
11
- require 'ice_cube/rule_occurrence'
3
+ # Use psych if we can
4
+ begin
5
+ require 'psych'
6
+ rescue LoadError
7
+ require 'yaml'
8
+ end
12
9
 
13
10
  module IceCube
14
-
11
+
12
+ autoload :VERSION, 'ice_cube/version'
13
+
14
+ autoload :TimeUtil, 'ice_cube/time_util'
15
+
16
+ autoload :Rule, 'ice_cube/rule'
17
+ autoload :Schedule, 'ice_cube/schedule'
18
+
19
+ autoload :IcalBuilder, 'ice_cube/builders/ical_builder'
20
+ autoload :HashBuilder, 'ice_cube/builders/hash_builder'
21
+ autoload :StringBuilder, 'ice_cube/builders/string_builder'
22
+
23
+ autoload :CountExceeded, 'ice_cube/errors/count_exceeded'
24
+ autoload :UntilExceeded, 'ice_cube/errors/until_exceeded'
25
+
26
+ autoload :ValidatedRule, 'ice_cube/validated_rule'
27
+ autoload :SingleOccurrenceRule, 'ice_cube/single_occurrence_rule'
28
+
29
+ autoload :SecondlyRule, 'ice_cube/rules/secondly_rule'
30
+ autoload :MinutelyRule, 'ice_cube/rules/minutely_rule'
31
+ autoload :HourlyRule, 'ice_cube/rules/hourly_rule'
15
32
  autoload :DailyRule, 'ice_cube/rules/daily_rule'
16
33
  autoload :WeeklyRule, 'ice_cube/rules/weekly_rule'
17
34
  autoload :MonthlyRule, 'ice_cube/rules/monthly_rule'
18
35
  autoload :YearlyRule, 'ice_cube/rules/yearly_rule'
19
-
20
- autoload :HourlyRule, 'ice_cube/rules/hourly_rule'
21
- autoload :MinutelyRule, 'ice_cube/rules/minutely_rule'
22
- autoload :SecondlyRule, 'ice_cube/rules/secondly_rule'
36
+
37
+ module Validations
38
+
39
+ autoload :Lock, 'ice_cube/validations/lock'
40
+ autoload :ScheduleLock, 'ice_cube/validations/schedule_lock'
41
+
42
+ autoload :Count, 'ice_cube/validations/count'
43
+ autoload :Until, 'ice_cube/validations/until'
44
+
45
+ autoload :SecondlyInterval, 'ice_cube/validations/secondly_interval'
46
+ autoload :MinutelyInterval, 'ice_cube/validations/minutely_interval'
47
+ autoload :DailyInterval, 'ice_cube/validations/daily_interval'
48
+ autoload :WeeklyInterval, 'ice_cube/validations/weekly_interval'
49
+ autoload :MonthlyInterval, 'ice_cube/validations/monthly_interval'
50
+ autoload :YearlyInterval, 'ice_cube/validations/yearly_interval'
51
+ autoload :HourlyInterval, 'ice_cube/validations/hourly_interval'
52
+
53
+ autoload :HourOfDay, 'ice_cube/validations/hour_of_day'
54
+ autoload :MonthOfYear, 'ice_cube/validations/month_of_year'
55
+ autoload :MinuteOfHour, 'ice_cube/validations/minute_of_hour'
56
+ autoload :SecondOfMinute, 'ice_cube/validations/second_of_minute'
57
+ autoload :DayOfMonth, 'ice_cube/validations/day_of_month'
58
+ autoload :DayOfWeek, 'ice_cube/validations/day_of_week'
59
+ autoload :Day, 'ice_cube/validations/day'
60
+ autoload :DayOfYear, 'ice_cube/validations/day_of_year'
61
+
62
+ end
63
+
64
+ # Define some useful constants
65
+ ONE_SECOND = 1
66
+ ONE_MINUTE = ONE_SECOND * 60
67
+ ONE_HOUR = ONE_MINUTE * 60
68
+ ONE_DAY = ONE_HOUR * 24
69
+ ONE_WEEK = ONE_DAY * 7
23
70
 
24
- autoload :DayValidation, 'ice_cube/validations/day'
25
- autoload :DayOfMonthValidation, 'ice_cube/validations/day_of_month'
26
- autoload :DayOfWeekValidation, 'ice_cube/validations/day_of_week'
27
- autoload :DayOfYearValidation, 'ice_cube/validations/day_of_year'
28
- autoload :HourOfDayValidation, 'ice_cube/validations/hour_of_day'
29
- autoload :MinuteOfHourValidation, 'ice_cube/validations/minute_of_hour'
30
- autoload :MonthOfYearValidation, 'ice_cube/validations/month_of_year'
31
- autoload :SecondOfMinuteValidation, 'ice_cube/validations/second_of_minute'
32
-
33
- # if you're reading this code, you've just been iced
34
- # http://brosicingbros.com/
35
-
36
- IceCube::ONE_DAY = 24 * 60 * 60
37
- IceCube::ONE_HOUR = 60 * 60
38
- IceCube::ONE_MINUTE = 60
39
- IceCube::ONE_SECOND = 1
40
-
41
- ICAL_DAYS = ['SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA']
42
- DAYS = { :sunday => 0, :monday => 1, :tuesday => 2, :wednesday => 3, :thursday => 4, :friday => 5, :saturday => 6 }
43
- MONTHS = { :january => 1, :february => 2, :march => 3, :april => 4, :may => 5, :june => 6, :july => 7, :august => 8,
44
- :september => 9, :october => 10, :november => 11, :december => 12 }
45
-
46
- include TimeUtil
71
+ # Formatting
72
+ TO_S_TIME_FORMAT = '%B %e, %Y'
47
73
 
48
74
  end
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + '/../lib/ice_cube'
2
+
3
+ begin
4
+ require 'cover_me'
5
+ # https://github.com/markbates/cover_me/issues/50
6
+ at_exit do
7
+ CoverMe.complete!
8
+ end
9
+ rescue LoadError
10
+ end
11
+
12
+ DAY = Time.utc(2010, 3, 1)
13
+ WEDNESDAY = Time.utc(2010, 6, 23, 5, 0, 0)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ice_cube
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.10
4
+ version: 0.7.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-07-31 00:00:00.000000000 -04:00
12
+ date: 2011-12-08 00:00:00.000000000 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
17
- requirement: &70363623868640 !ruby/object:Gem::Requirement
17
+ requirement: &70154139759660 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,7 +22,29 @@ dependencies:
22
22
  version: '0'
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *70363623868640
25
+ version_requirements: *70154139759660
26
+ - !ruby/object:Gem::Dependency
27
+ name: active_support
28
+ requirement: &70154139758460 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 3.0.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *70154139758460
37
+ - !ruby/object:Gem::Dependency
38
+ name: tzinfo
39
+ requirement: &70154139757400 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *70154139757400
26
48
  description: ice_cube is a recurring date library for Ruby. It allows for quick,
27
49
  programatic expansion of recurring date rules.
28
50
  email: john@crepezzi.com
@@ -30,8 +52,12 @@ executables: []
30
52
  extensions: []
31
53
  extra_rdoc_files: []
32
54
  files:
55
+ - lib/ice_cube/builders/hash_builder.rb
56
+ - lib/ice_cube/builders/ical_builder.rb
57
+ - lib/ice_cube/builders/string_builder.rb
58
+ - lib/ice_cube/errors/count_exceeded.rb
59
+ - lib/ice_cube/errors/until_exceeded.rb
33
60
  - lib/ice_cube/rule.rb
34
- - lib/ice_cube/rule_occurrence.rb
35
61
  - lib/ice_cube/rules/daily_rule.rb
36
62
  - lib/ice_cube/rules/hourly_rule.rb
37
63
  - lib/ice_cube/rules/minutely_rule.rb
@@ -40,19 +66,31 @@ files:
40
66
  - lib/ice_cube/rules/weekly_rule.rb
41
67
  - lib/ice_cube/rules/yearly_rule.rb
42
68
  - lib/ice_cube/schedule.rb
69
+ - lib/ice_cube/single_occurrence_rule.rb
43
70
  - lib/ice_cube/time_util.rb
44
- - lib/ice_cube/validation.rb
45
- - lib/ice_cube/validation_types.rb
71
+ - lib/ice_cube/validated_rule.rb
72
+ - lib/ice_cube/validations/count.rb
73
+ - lib/ice_cube/validations/daily_interval.rb
46
74
  - lib/ice_cube/validations/day.rb
47
75
  - lib/ice_cube/validations/day_of_month.rb
48
76
  - lib/ice_cube/validations/day_of_week.rb
49
77
  - lib/ice_cube/validations/day_of_year.rb
50
78
  - lib/ice_cube/validations/hour_of_day.rb
79
+ - lib/ice_cube/validations/hourly_interval.rb
80
+ - lib/ice_cube/validations/lock.rb
51
81
  - lib/ice_cube/validations/minute_of_hour.rb
82
+ - lib/ice_cube/validations/minutely_interval.rb
52
83
  - lib/ice_cube/validations/month_of_year.rb
84
+ - lib/ice_cube/validations/monthly_interval.rb
85
+ - lib/ice_cube/validations/schedule_lock.rb
53
86
  - lib/ice_cube/validations/second_of_minute.rb
87
+ - lib/ice_cube/validations/secondly_interval.rb
88
+ - lib/ice_cube/validations/until.rb
89
+ - lib/ice_cube/validations/weekly_interval.rb
90
+ - lib/ice_cube/validations/yearly_interval.rb
54
91
  - lib/ice_cube/version.rb
55
92
  - lib/ice_cube.rb
93
+ - spec/spec_helper.rb
56
94
  has_rdoc: true
57
95
  homepage: http://seejohnrun.github.com/ice_cube/
58
96
  licenses: []
@@ -78,4 +116,5 @@ rubygems_version: 1.6.2
78
116
  signing_key:
79
117
  specification_version: 3
80
118
  summary: Ruby Date Recurrence Library
81
- test_files: []
119
+ test_files:
120
+ - spec/spec_helper.rb
@@ -1,100 +0,0 @@
1
- module IceCube
2
-
3
- class RuleOccurrence
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
10
-
11
- def to_time
12
- @date
13
- end
14
-
15
- def all_occurrences
16
- raise ArgumentError.new("Rule must specify either an until date or a count to use 'all_occurrences'") unless @rule.occurrence_count || @rule.until_date || @end_time
17
- find_occurrences { |roc| false }
18
- end
19
-
20
- def between(begin_time, end_time)
21
- find_occurrences { |roc| roc > end_time }.select { |d| d >= begin_time }
22
- end
23
-
24
- def upto(end_date)
25
- find_occurrences { |roc| roc > end_date }
26
- end
27
-
28
- # Break after the first occurrence after now
29
- def next_occurrence(from)
30
- next_occurrences(1, from).first
31
- end
32
-
33
- # Break after the first n occurrences after now
34
- def next_occurrences(n, from)
35
- found_all = false
36
- num_found = 0
37
- nexts = find_occurrences do |roc|
38
- find = roc > from
39
- num_found += 1 if find
40
- success = found_all
41
- found_all = num_found == n
42
- success
43
- end
44
- #Since the above returns all up to and including the next N that were requested, we need
45
- #to grab the last n, making sure to prune out ones that were actually before the from time
46
- nexts.last(n).select{|occurrence| occurrence > from}
47
- end
48
-
49
- def first(n)
50
- count = 0
51
- find_occurrences { |roc| count += 1; count > n }
52
- end
53
-
54
- #get the next occurrence of this rule
55
- def succ
56
- return nil if @rule.occurrence_count && @index >= @rule.occurrence_count # count check
57
- # get the next date to walk to
58
- if @date.nil?
59
- date = @start_date if @rule.validate_single_date(@start_date)
60
- date = @rule.next_suggestion(@start_date) unless date
61
- else
62
- date = @rule.next_suggestion(@date)
63
- end
64
- # walk through all of the successive dates, looking for the next occurrence (interval-valid), then return it.
65
- begin
66
- return nil if @end_time && date > @end_time
67
- return nil if @rule.until_date && date > @rule.until_date # until check
68
- next unless @rule.in_interval?(date, @start_date)
69
- return nil if yield(date)
70
- return RuleOccurrence.new(@rule, @start_date, @end_time, date, @index + 1)
71
- end while date = @rule.next_suggestion(date)
72
- end
73
-
74
- attr_reader :rule
75
-
76
- private
77
-
78
- def find_occurrences(&block)
79
- include_dates = []
80
- roc = self
81
- begin
82
- break if roc.nil? #go until we run out of dates
83
- next if roc.to_time.nil? #handle the case where start_date is not a valid occurrence
84
- include_dates << roc.to_time
85
- end while roc = roc.succ(&block)
86
- include_dates
87
- end
88
-
89
- def initialize(rule, start_date, end_time, date = nil, index = 0)
90
- #set some variables
91
- @rule = rule
92
- @start_date = start_date
93
- @end_time = end_time
94
- @date = date
95
- @index = index
96
- end
97
-
98
- end
99
-
100
- end
@@ -1,44 +0,0 @@
1
- module IceCube
2
-
3
- class Validation
4
-
5
- NUMBER_SUFFIX = ['th', 'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th']
6
- SPECIAL_SUFFIX = { 11 => 'th', 12 => 'th', 13 => 'th', 14 => 'th' }
7
-
8
- def self.adjust(goal, date)
9
- return goal if goal.utc_offset == date.utc_offset
10
- goal - goal.utc_offset + date.utc_offset
11
- end
12
-
13
- # influences by ActiveSupport's to_sentence
14
- def self.sentence(array)
15
- case array.length
16
- when 0 ; ''
17
- when 1 ; array[0].to_s
18
- when 2 ; "#{array[0]} and #{array[1]}"
19
- else ; "#{array[0...-1].join(', ')}, and #{array[-1]}"
20
- end
21
- end
22
-
23
- def self.nice_numbers(array)
24
- array.sort!
25
- self.sentence array.map { |d| nice_number(d) }
26
- end
27
-
28
- private
29
-
30
- def self.nice_number(number)
31
- if number == -1
32
- 'last'
33
- elsif number < -1
34
- suffix = SPECIAL_SUFFIX.include?(number) ? SPECIAL_SUFFIX[number] : NUMBER_SUFFIX[number.abs % 10]
35
- number.abs.to_s << suffix << ' to last'
36
- else
37
- suffix = SPECIAL_SUFFIX.include?(number) ? SPECIAL_SUFFIX[number] : NUMBER_SUFFIX[number.abs % 10]
38
- number.to_s << suffix
39
- end
40
- end
41
-
42
- end
43
-
44
- end