Class: RiCal::PropertyValue

Inherits:
Object show all
Defined in:
lib/ri_cal/property_value.rb,
lib/ri_cal/property_value/geo.rb,
lib/ri_cal/property_value/uri.rb,
lib/ri_cal/property_value/date.rb,
lib/ri_cal/property_value/text.rb,
lib/ri_cal/property_value/array.rb,
lib/ri_cal/property_value/period.rb,
lib/ri_cal/property_value/integer.rb,
lib/ri_cal/property_value/duration.rb,
lib/ri_cal/property_value/date_time.rb,
lib/ri_cal/property_value/utc_offset.rb,
lib/ri_cal/property_value/cal_address.rb,
lib/ri_cal/property_value/zulu_date_time.rb,
lib/ri_cal/property_value/occurrence_list.rb,
lib/ri_cal/property_value/recurrence_rule.rb,
lib/ri_cal/property_value/date_time/time_machine.rb,
lib/ri_cal/property_value/date_time/additive_methods.rb,
lib/ri_cal/property_value/date_time/timezone_support.rb,
lib/ri_cal/property_value/recurrence_rule/enumerator.rb,
lib/ri_cal/property_value/recurrence_rule/validations.rb,
lib/ri_cal/property_value/recurrence_rule/numbered_span.rb,
lib/ri_cal/property_value/recurrence_rule/recurring_day.rb,
lib/ri_cal/property_value/recurrence_rule/time_manipulation.rb,
lib/ri_cal/property_value/recurrence_rule/recurring_year_day.rb,
lib/ri_cal/property_value/recurrence_rule/recurring_month_day.rb,
lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/recurring_numbered_week.rb,
lib/ri_cal/property_value/recurrence_rule/negative_setpos_enumerator.rb,
lib/ri_cal/property_value/recurrence_rule/enumeration_support_methods.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/list_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/daily_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_day_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/hourly_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/weekly_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/yearly_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_hour_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/monthly_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_month_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/minutely_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/secondly_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_minute_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_second_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_weekno_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/frequency_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_yearday_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_monthday_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/null_sub_cycle_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_numbered_day_incrementer.rb

Overview

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

PropertyValue provides common implementation of various RFC 2445 property value types

Defined Under Namespace

Classes: Array, CalAddress, Date, DateTime, Duration, Geo, Integer, OccurrenceList, Period, RecurrenceRule, Text, Uri, UtcOffset, ZuluDateTime

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(timezone_finder, options = {}) ⇒ PropertyValue

:nodoc:



24
25
26
27
28
29
30
31
32
33
# File 'lib/ri_cal/property_value.rb', line 24

def initialize(timezone_finder, options={}) # :nodoc:
  @timezone_finder = timezone_finder
  validate_value(options)
  ({:params => {}}).merge(options).each do |attribute, val|
    unless attribute == :name
      setter = :"#{attribute.to_s.downcase}="
      send(setter, val)
    end
  end
end

Instance Attribute Details

#paramsObject

return a hash containing the parameters and values, if any



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

def params
  @params ||= {}
end

#timezone_finderObject (readonly)

:nodoc:



23
24
25
# File 'lib/ri_cal/property_value.rb', line 23

def timezone_finder
  @timezone_finder
end

#valueObject

Return the string value



100
101
102
# File 'lib/ri_cal/property_value.rb', line 100

def value
  @value
end

Class Method Details

.convert(timezone_finder, value) ⇒ Object

def self.from_string(string) # :nodoc:

new(nil, :value => string)

end



86
87
88
# File 'lib/ri_cal/property_value.rb', line 86

def self.convert(timezone_finder, value) #:nodoc:
  new(timezone_finder, :value => value)
end

.date_or_date_time(timezone_finder, separated_line) ⇒ Object

:nodoc:

Raises:

  • (Exception)


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/ri_cal/property_value.rb', line 58

def self.date_or_date_time(timezone_finder, separated_line) # :nodoc:
  match = separated_line[:value].match(/(\d\d\d\d)(\d\d)(\d\d)((T?)((\d\d)(\d\d)(\d\d))(Z?))?/)
  raise Exception.new("Invalid date") unless match
  if match[5] == "T" # date-time
    time = Time.utc(match[1].to_i, match[2].to_i, match[3].to_i, match[7].to_i, match[8].to_i, match[9].to_i)
    parms = (separated_line[:params] ||{}).dup
    if match[10] == "Z"
      raise Exception.new("Invalid time, cannot combine Zulu with timezone reference") if parms[:tzid]
      parms['TZID'] = "UTC"
    end
    PropertyValue::DateTime.new(timezone_finder, separated_line.merge(:params => parms))
  else
    PropertyValue::Date.new(timezone_finder, separated_line)
  end
end

.date_or_date_time_or_period(timezone_finder, separated_line) ⇒ Object

:nodoc:



74
75
76
77
78
79
80
# File 'lib/ri_cal/property_value.rb', line 74

def self.date_or_date_time_or_period(timezone_finder, separated_line) #:nodoc:
  if separated_line[:value].include?("/")
    PropertyValue::Period.new(timezone_finder, separated_line)
  else
    date_or_date_time(timezone_finder, separated_line)
  end
end

.if_valid_string(timezone_finder, string) ⇒ Object

:nodoc:



35
36
37
38
39
40
41
# File 'lib/ri_cal/property_value.rb', line 35

def self.if_valid_string(timezone_finder, string) #:nodoc:
  if valid_string?(string)
    new(timezone_finder, :value => string)
  else
    nil
  end
end

Instance Method Details

#==(o) ⇒ Object

Determine if another object is equivalent to the receiver.



91
92
93
94
95
96
97
# File 'lib/ri_cal/property_value.rb', line 91

def ==(o)
  if o.class == self.class
    equality_value == o.equality_value
  else
    super
  end
end

#add_date_times_to(required_timezones) ⇒ Object

:nodoc:



135
136
137
138
139
140
141
# File 'lib/ri_cal/property_value/occurrence_list.rb', line 135

def add_date_times_to(required_timezones) #:nodoc:
  if @elements
    @elements.each do | occurrence |
      occurrence.add_date_times_to(required_timezones)
    end
  end
end

#default_tzidObject

:nodoc:



143
144
145
146
147
148
149
# File 'lib/ri_cal/property_value.rb', line 143

def default_tzid #:nodoc:
  if timezone_finder
    timezone_finder.default_tzid
  else
    PropertyValue::DateTime.default_tzid
  end
end

#enumerator(component) ⇒ Object

Return an enumerator which can produce the elements of the occurrence list



131
132
133
# File 'lib/ri_cal/property_value/occurrence_list.rb', line 131

def enumerator(component) # :nodoc:
  OccurrenceList::Enumerator.new(@elements, component)
end

#equality_valueObject

:nodoc:



104
105
106
# File 'lib/ri_cal/property_value.rb', line 104

def equality_value #:nodoc:
  value
end

#find_timezone(timezone_identifier) ⇒ Object

:nodoc:



135
136
137
138
139
140
141
# File 'lib/ri_cal/property_value.rb', line 135

def find_timezone(timezone_identifier) #:nodoc:
  if timezone_finder
    timezone_finder.find_timezone(timezone_identifier)
  else
    raise "Unable to find timezone with tzid #{timezone_identifier}"
  end
end

#for_parent(parent) ⇒ Object

:nodoc:



119
120
121
122
123
124
125
126
127
128
# File 'lib/ri_cal/property_value/occurrence_list.rb', line 119

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

#parms_stringObject

:nodoc:



112
113
114
115
116
117
118
119
# File 'lib/ri_cal/property_value.rb', line 112

def parms_string #:nodoc:
  if (vp = visible_params) && !vp.empty?
    # We only sort for testability reasons
    vp.keys.sort.map {|key| ";#{key}=#{vp[key]}"}.join
  else
    ""
  end
end

#ruby_valueObject

return the ruby value



127
128
129
# File 'lib/ri_cal/property_value.rb', line 127

def ruby_value
  self.value
end

#to_options_hashObject

:nodoc:



53
54
55
56
# File 'lib/ri_cal/property_value.rb', line 53

def to_options_hash #:nodoc:
  options_hash = {:value => value}
  options_hash[:params] = params unless params.empty?
end

#to_ri_cal_property_valueObject

:nodoc:



131
132
133
# File 'lib/ri_cal/property_value.rb', line 131

def to_ri_cal_property_value #:nodoc:
  self
end

#to_sObject

Return a string representing the receiver in RFC 2445 format



122
123
124
# File 'lib/ri_cal/property_value.rb', line 122

def to_s #:nodoc:
  "#{parms_string}:#{value}"
end

#tz_info_source?Boolean

:nodoc:

Returns:

  • (Boolean)


151
152
153
154
155
156
157
# File 'lib/ri_cal/property_value.rb', line 151

def tz_info_source? #:nodoc:
  if timezone_finder
    timezone_finder.tz_info_source?
  else
    true
  end
end

#validate_value(options) ⇒ Object

:nodoc:



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

def validate_value(options) #:nodoc:
  val = options[:value]
  raise "Invalid property value #{val.inspect}" if val.kind_of?(String) && /^;/.match(val)
end

#visible_paramsObject

:nodoc:



108
109
110
# File 'lib/ri_cal/property_value.rb', line 108

def visible_params # :nodoc:
  params
end