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

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

Overview

:nodoc:

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.



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

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



6
7
8
# File 'lib/ri_cal/property_value/recurrence_rule/enumerator.rb', line 6

def base_time
  @base_time
end

#durationObject

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



6
7
8
# File 'lib/ri_cal/property_value/recurrence_rule/enumerator.rb', line 6

def duration
  @duration
end

#next_timeObject

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



6
7
8
# File 'lib/ri_cal/property_value/recurrence_rule/enumerator.rb', line 6

def next_time
  @next_time
end

#recurrence_ruleObject

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



6
7
8
# File 'lib/ri_cal/property_value/recurrence_rule/enumerator.rb', line 6

def recurrence_rule
  @recurrence_rule
end

#start_timeObject

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



6
7
8
# File 'lib/ri_cal/property_value/recurrence_rule/enumerator.rb', line 6

def start_time
  @start_time
end

Class Method Details

.for(recurrence_rule, component, setpos_list) ⇒ Object

:nodoc:



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

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)


33
34
35
# File 'lib/ri_cal/property_value/recurrence_rule/enumerator.rb', line 33

def bounded?
  @bounded
end

#empty?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/ri_cal/property_value/recurrence_rule/enumerator.rb', line 29

def empty?
  false
end

#next_occurrenceObject



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

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



37
38
39
# File 'lib/ri_cal/property_value/recurrence_rule/enumerator.rb', line 37

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

#result_passes_filters?(result) ⇒ Boolean

Returns:

  • (Boolean)


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

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)


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

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