Class: Icalendar::Recurrence::Schedule
- Inherits:
-
Object
- Object
- Icalendar::Recurrence::Schedule
- Defined in:
- lib/icalendar/recurrence/schedule.rb
Instance Attribute Summary collapse
-
#event ⇒ Object
readonly
Returns the value of attribute event.
Instance Method Summary collapse
- #all_occurrences ⇒ Object
- #convert_ice_cube_occurrence(ice_cube_occurrence) ⇒ Object
- #end_time ⇒ Object
- #ice_cube_schedule ⇒ Object
-
#initialize(event) ⇒ Schedule
constructor
A new instance of Schedule.
- #occurrences_between(begin_time, closing_time) ⇒ Object
- #rrules ⇒ Object
- #start_time ⇒ Object
- #timezone ⇒ Object
Constructor Details
#initialize(event) ⇒ Schedule
Returns a new instance of Schedule.
11 12 13 |
# File 'lib/icalendar/recurrence/schedule.rb', line 11 def initialize(event) @event = event end |
Instance Attribute Details
#event ⇒ Object (readonly)
Returns the value of attribute event.
9 10 11 |
# File 'lib/icalendar/recurrence/schedule.rb', line 9 def event @event end |
Instance Method Details
#all_occurrences ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/icalendar/recurrence/schedule.rb', line 43 def all_occurrences ice_cube_occurrences = ice_cube_schedule.all_occurrences ice_cube_occurrences.map do |occurrence| convert_ice_cube_occurrence(occurrence) end end |
#convert_ice_cube_occurrence(ice_cube_occurrence) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/icalendar/recurrence/schedule.rb', line 51 def convert_ice_cube_occurrence(ice_cube_occurrence) if timezone begin tz = TZInfo::Timezone.get(timezone) start_time = tz.local_to_utc(ice_cube_occurrence.start_time) end_time = tz.local_to_utc(ice_cube_occurrence.end_time) rescue TZInfo::InvalidTimezoneIdentifier => e warn "Unknown TZID specified in ical event (#{timezone.inspect}), ignoring (will likely cause event to be at wrong time!)" end end start_time ||= ice_cube_occurrence.start_time end_time ||= ice_cube_occurrence.end_time Icalendar::Recurrence::Occurrence.new(start_time, end_time) end |
#end_time ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/icalendar/recurrence/schedule.rb', line 27 def end_time if event.end TimeUtil.to_time(event.end) else start_time + convert_duration_to_seconds(event.duration) end end |
#ice_cube_schedule ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/icalendar/recurrence/schedule.rb', line 68 def ice_cube_schedule schedule = IceCube::Schedule.new schedule.start_time = start_time schedule.end_time = end_time rrules.each do |rrule| ice_cube_recurrence_rule = IceCube::Rule.from_ical(rrule.value_ical) schedule.add_recurrence_rule(ice_cube_recurrence_rule) end event.exdate.each do |exception_date| exception_date = Time.parse(exception_date) if exception_date.is_a?(String) schedule.add_exception_time(TimeUtil.to_time(exception_date)) end schedule end |
#occurrences_between(begin_time, closing_time) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/icalendar/recurrence/schedule.rb', line 35 def occurrences_between(begin_time, closing_time) ice_cube_occurrences = ice_cube_schedule.occurrences_between(TimeUtil.to_time(begin_time), TimeUtil.to_time(closing_time)) ice_cube_occurrences.map do |occurrence| convert_ice_cube_occurrence(occurrence) end end |
#rrules ⇒ Object
19 20 21 |
# File 'lib/icalendar/recurrence/schedule.rb', line 19 def rrules event.rrule end |
#start_time ⇒ Object
23 24 25 |
# File 'lib/icalendar/recurrence/schedule.rb', line 23 def start_time TimeUtil.to_time(event.start) end |
#timezone ⇒ Object
15 16 17 |
# File 'lib/icalendar/recurrence/schedule.rb', line 15 def timezone event.tzid end |