Class: RiCal::PropertyValue::RecurrenceRule::Enumerator

Inherits:
Object
  • Object
show all
Defined in:
lib/ri_cal/property_value/recurrence_rule/enumerator.rb

Overview

  • ©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license

Direct Known Subclasses

NegativeSetposEnumerator

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(recurrence_rule, component, setpos_list) ⇒ Enumerator

Returns a new instance of Enumerator


9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ri_cal/property_value/recurrence_rule/enumerator.rb', line 9

def initialize(recurrence_rule, component, setpos_list)
  self.recurrence_rule = recurrence_rule
  self.start_time = component.default_start_time
  self.duration = component.default_duration
  self.next_time = recurrence_rule.adjust_start(self.start_time)
  self.base_time = next_time
  @bounded = recurrence_rule.bounded?
  @count = 0
  @setpos_list = setpos_list
  @setpos = 1
  @next_occurrence_count = 0
  @incrementer = recurrence_rule.incrementer_from_start_time(start_time)
end

Instance Attribute Details

#base_timeObject

base_time gets changed everytime the time is updated by the recurrence rule's frequency


8
9
10
# File 'lib/ri_cal/property_value/recurrence_rule/enumerator.rb', line 8

def base_time
  @base_time
end

#durationObject

base_time gets changed everytime the time is updated by the recurrence rule's frequency


8
9
10
# File 'lib/ri_cal/property_value/recurrence_rule/enumerator.rb', line 8

def duration
  @duration
end

#next_timeObject

base_time gets changed everytime the time is updated by the recurrence rule's frequency


8
9
10
# File 'lib/ri_cal/property_value/recurrence_rule/enumerator.rb', line 8

def next_time
  @next_time
end

#recurrence_ruleObject

base_time gets changed everytime the time is updated by the recurrence rule's frequency


8
9
10
# File 'lib/ri_cal/property_value/recurrence_rule/enumerator.rb', line 8

def recurrence_rule
  @recurrence_rule
end

#start_timeObject

base_time gets changed everytime the time is updated by the recurrence rule's frequency


8
9
10
# File 'lib/ri_cal/property_value/recurrence_rule/enumerator.rb', line 8

def start_time
  @start_time
end

Class Method Details

.for(recurrence_rule, component, setpos_list) ⇒ Object

:nodoc:


23
24
25
26
27
28
29
# File 'lib/ri_cal/property_value/recurrence_rule/enumerator.rb', line 23

def self.for(recurrence_rule, component, setpos_list) # :nodoc:
  if !setpos_list || setpos_list.all? {|setpos| setpos > 1}
    self.new(recurrence_rule, component, setpos_list)
  else
    NegativeSetposEnumerator.new(recurrence_rule, component, setpos_list)
  end
end

Instance Method Details

#bounded?Boolean

Returns:

  • (Boolean)

35
36
37
# File 'lib/ri_cal/property_value/recurrence_rule/enumerator.rb', line 35

def bounded?
  @bounded
end

#empty?Boolean

Returns:

  • (Boolean)

31
32
33
# File 'lib/ri_cal/property_value/recurrence_rule/enumerator.rb', line 31

def empty?
  false
end

#next_occurrenceObject


65
66
67
68
69
70
71
72
73
74
75
# File 'lib/ri_cal/property_value/recurrence_rule/enumerator.rb', line 65

def next_occurrence
  while true
    @next_occurrence_count += 1
    result = next_time
    self.next_time = @incrementer.next_time(result)
    if result_passes_filters?(result)
      @count += 1
      return recurrence_rule.exhausted?(@count, result) ? nil : result_occurrence_period(result)
    end
  end
end

#result_occurrence_period(date_time_value) ⇒ Object


39
40
41
# File 'lib/ri_cal/property_value/recurrence_rule/enumerator.rb', line 39

def result_occurrence_period(date_time_value)
  RiCal::OccurrencePeriod.new(date_time_value, nil)
end

#result_passes_filters?(result) ⇒ Boolean

Returns:

  • (Boolean)

57
58
59
60
61
62
63
# File 'lib/ri_cal/property_value/recurrence_rule/enumerator.rb', line 57

def result_passes_filters?(result)
  if @setpos_list
    result_passes_setpos_filter?(result)
  else
    result >= start_time
  end
end

#result_passes_setpos_filter?(result) ⇒ Boolean

Returns:

  • (Boolean)

43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ri_cal/property_value/recurrence_rule/enumerator.rb', line 43

def result_passes_setpos_filter?(result)
  result_setpos = @setpos
  if recurrence_rule.in_same_set?(result, next_time)
    @setpos += 1
  else
    @setpos = 1
  end
  if (result == start_time) || (result > start_time && @setpos_list.include?(result_setpos))
    return true
  else
    return false
  end
end