Class: IceCube::RuleOccurrence
- Inherits:
-
Object
- Object
- IceCube::RuleOccurrence
- Includes:
- Comparable
- Defined in:
- lib/ice_cube/rule_occurrence.rb
Instance Attribute Summary collapse
-
#rule ⇒ Object
readonly
Returns the value of attribute rule.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
allow to be compared to dates.
- #all_occurrences ⇒ Object
- #between(begin_time, end_time) ⇒ Object
- #first(n) ⇒ Object
-
#succ ⇒ Object
get the next occurrence of this rule.
- #to_time ⇒ Object
- #upto(end_date) ⇒ Object
Instance Attribute Details
#rule ⇒ Object (readonly)
Returns the value of attribute rule.
51 52 53 |
# File 'lib/ice_cube/rule_occurrence.rb', line 51 def rule @rule end |
Instance Method Details
#<=>(other) ⇒ Object
allow to be compared to dates
8 9 10 |
# File 'lib/ice_cube/rule_occurrence.rb', line 8 def <=>(other) to_time <=> other end |
#all_occurrences ⇒ Object
16 17 18 19 |
# File 'lib/ice_cube/rule_occurrence.rb', line 16 def all_occurrences raise ArgumentError.new("Rule must specify either an until date or a count to use 'all_occurrences'") unless @rule.occurrence_count || @rule.until_date find_occurrences { |roc| false } end |
#between(begin_time, end_time) ⇒ Object
21 22 23 |
# File 'lib/ice_cube/rule_occurrence.rb', line 21 def between(begin_time, end_time) find_occurrences { |roc| roc > end_time }.select { |d| d >= begin_time } end |
#first(n) ⇒ Object
29 30 31 32 |
# File 'lib/ice_cube/rule_occurrence.rb', line 29 def first(n) count = 0 find_occurrences { |roc| count += 1; count > n } end |
#succ ⇒ Object
get the next occurrence of this rule
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ice_cube/rule_occurrence.rb', line 35 def succ return nil if @rule.occurrence_count && @index >= @rule.occurrence_count # count check # get the next date to walk to if @date.nil? date = @start_date if @rule.validate_single_date(@start_date) date = @rule.next_suggestion(@start_date) unless date else date = @rule.next_suggestion(@date) end #walk through all of the successive dates, looking for the next occurrence (interval-valid), then return it. begin return nil if @rule.until_date && date > @rule.until_date # until check return RuleOccurrence.new(@rule, @start_date, date, @index + 1) if @rule.in_interval?(date, @start_date) end while date = @rule.next_suggestion(date) end |
#to_time ⇒ Object
12 13 14 |
# File 'lib/ice_cube/rule_occurrence.rb', line 12 def to_time @date end |
#upto(end_date) ⇒ Object
25 26 27 |
# File 'lib/ice_cube/rule_occurrence.rb', line 25 def upto(end_date) find_occurrences { |roc| roc > end_date } end |