Class: RiCal::PropertyValue::Period

Inherits:
RiCal::PropertyValue show all
Defined in:
lib/ri_cal/property_value/period.rb

Overview

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

RiCal::PropertyValue::CalAddress represents an icalendar Period property value which is defined in rfc 2445 section 4.3.9 p 39

Known bugs. This doesn’t properly work when dtstart, dtend or duration are changed independently

Instance Attribute Summary collapse

Attributes inherited from RiCal::PropertyValue

#params, #timezone_finder, #value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RiCal::PropertyValue

#==, date_or_date_time, date_or_date_time_or_period, #default_tzid, #enumerator, #equality_value, #find_timezone, if_valid_string, #initialize, #parms_string, #ruby_value, #to_options_hash, #to_ri_cal_property_value, #to_s, #tz_info_source?, #validate_value, #visible_params

Constructor Details

This class inherits a constructor from RiCal::PropertyValue

Instance Attribute Details

#dtendObject

The DATE-TIME on which the period ends



15
16
17
# File 'lib/ri_cal/property_value/period.rb', line 15

def dtend
  @dtend
end

#dtstartObject

The DATE-TIME on which the period starts



13
14
15
# File 'lib/ri_cal/property_value/period.rb', line 13

def dtstart
  @dtstart
end

#durationObject

The DURATION of the period



17
18
19
# File 'lib/ri_cal/property_value/period.rb', line 17

def duration
  @duration
end

Class Method Details

.convert(parent, ruby_object) ⇒ Object

:nodoc:



63
64
65
# File 'lib/ri_cal/property_value/period.rb', line 63

def self.convert(parent, ruby_object) # :nodoc:
  ruby_object.to_ri_cal_period_value.for_parent(parent)
end

.valid_string?(string) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ri_cal/property_value/period.rb', line 32

def self.valid_string?(string) # :nodoc:
  return false unless string.include?("/")
  starter, terminator = *string.split("/")
  return false unless PropertyValue::DateTime.valid_string?(starter)
  if /P/ =~ terminator
    return false unless PropertyValue::Duration.valid_string?(terminator)
  else
    return false unless PropertyValue::DateTime.valid_string?(terminator)
  end
  true
end

Instance Method Details

#add_date_times_to(required_timezones) ⇒ Object

:nodoc:



76
77
78
79
# File 'lib/ri_cal/property_value/period.rb', line 76

def add_date_times_to(required_timezones) #:nodoc:
  dtstart.add_date_times_to(required_timezones)
  dtend.add_date_times_to(required_timezones)
end

#for_parent(parent) ⇒ Object

:nodoc:



52
53
54
55
56
57
58
59
60
61
# File 'lib/ri_cal/property_value/period.rb', line 52

def for_parent(parent) #:nodoc:
  if timezone_finder.nil
    @timezone_finder = parent
    self
  elsif timezone_finder == parent
    self
  else
    Period.new(parent, :value => value)
  end
end

#occurrence_period(default_duration) ⇒ Object

:nodoc:



72
73
74
# File 'lib/ri_cal/property_value/period.rb', line 72

def occurrence_period(default_duration) #:nodoc:
  RiCal::OccurrencePeriod.new(self, (default_duration ? self + default_duration : nil))
end

#to_ri_cal_period_valueObject

return the receiver



68
69
70
# File 'lib/ri_cal/property_value/period.rb', line 68

def to_ri_cal_period_value
  self
end

#tzidObject

:nodoc:



48
49
50
# File 'lib/ri_cal/property_value/period.rb', line 48

def tzid #:nodoc:
  nil
end

#tzid=(val) ⇒ Object

Nop to allow occurrence list to try to set it



45
46
# File 'lib/ri_cal/property_value/period.rb', line 45

def tzid=(val)#:nodoc:
end

#value=(string) ⇒ Object

:nodoc:



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ri_cal/property_value/period.rb', line 19

def value=(string) # :nodoc:
  starter, terminator = *string.split("/")
  self.dtstart = PropertyValue::DateTime.new(self, :value => starter)
  if /P/ =~ terminator
    self.duration = PropertyValue::Duration.new(self, :value => terminator)
    self.dtend = dtstart + duration
  else
    self.dtend   = PropertyValue::DateTime.new(self, :value => terminator)
    self.duration = PropertyValue::Duration.from_datetimes(self, dtstart.to_datetime, dtend.to_datetime)        
  end
end