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

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:



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

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



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

def params
  @params ||= {}
end

#timezone_finderObject (readonly)

:nodoc:



21
22
23
# File 'lib/ri_cal/property_value.rb', line 21

def timezone_finder
  @timezone_finder
end

#valueObject

Return the string value



98
99
100
# File 'lib/ri_cal/property_value.rb', line 98

def value
  @value
end

Class Method Details

.convert(timezone_finder, value) ⇒ Object

def self.from_string(string) # :nodoc:

new(nil, :value => string)

end



84
85
86
# File 'lib/ri_cal/property_value.rb', line 84

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)


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

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:



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

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:



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

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.



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

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

#add_date_times_to(required_timezones) ⇒ Object

:nodoc:



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

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:



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

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



129
130
131
# File 'lib/ri_cal/property_value/occurrence_list.rb', line 129

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

#equality_valueObject

:nodoc:



102
103
104
# File 'lib/ri_cal/property_value.rb', line 102

def equality_value #:nodoc:
  value
end

#find_timezone(timezone_identifier) ⇒ Object

:nodoc:



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

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:



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

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:



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

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



125
126
127
# File 'lib/ri_cal/property_value.rb', line 125

def ruby_value
  self.value
end

#to_options_hashObject

:nodoc:



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

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

#to_ri_cal_property_valueObject

:nodoc:



129
130
131
# File 'lib/ri_cal/property_value.rb', line 129

def to_ri_cal_property_value #:nodoc:
  self
end

#to_sObject

Return a string representing the receiver in RFC 2445 format



120
121
122
# File 'lib/ri_cal/property_value.rb', line 120

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

#tz_info_source?Boolean

:nodoc:

Returns:

  • (Boolean)


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

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

#validate_value(options) ⇒ Object

:nodoc:



41
42
43
44
# File 'lib/ri_cal/property_value.rb', line 41

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:



106
107
108
# File 'lib/ri_cal/property_value.rb', line 106

def visible_params # :nodoc:
  params
end