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, #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:



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

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)


36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ri_cal/property_value/period.rb', line 36

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:



80
81
82
83
# File 'lib/ri_cal/property_value/period.rb', line 80

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:



56
57
58
59
60
61
62
63
64
65
# File 'lib/ri_cal/property_value/period.rb', line 56

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:



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

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

#ruby_valueObject



32
33
34
# File 'lib/ri_cal/property_value/period.rb', line 32

def ruby_value
  self
end

#to_ri_cal_period_valueObject

return the receiver



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

def to_ri_cal_period_value
  self
end

#tzidObject

:nodoc:



52
53
54
# File 'lib/ri_cal/property_value/period.rb', line 52

def tzid #:nodoc:
  nil
end

#tzid=(val) ⇒ Object

Nop to allow occurrence list to try to set it



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

def tzid=(val)#:nodoc:
end

#value=(string) ⇒ Object

:nodoc:



19
20
21
22
23
24
25
26
27
28
29
30
# 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
  @value = string
end