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/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/recurring_year_day.rb,
lib/ri_cal/property_value/recurrence_rule/recurring_month_day.rb,
lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/initialization_methods.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

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

:nodoc:



9
10
11
12
13
14
15
16
17
18
# File 'lib/ri_cal/property_value.rb', line 9

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



34
35
36
# File 'lib/ri_cal/property_value.rb', line 34

def params
  @params ||= {}
end

#timezone_finderObject (readonly)

:nodoc:



8
9
10
# File 'lib/ri_cal/property_value.rb', line 8

def timezone_finder
  @timezone_finder
end

#valueObject

Return the string value



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

def value
  @value
end

Class Method Details

.convert(timezone_finder, value) ⇒ Object

def self.from_string(string) # :nodoc:

new(nil, :value => string)

end



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

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)


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ri_cal/property_value.rb', line 43

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:



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

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:



20
21
22
23
24
25
26
# File 'lib/ri_cal/property_value.rb', line 20

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.



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

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:



128
129
130
131
132
133
134
# File 'lib/ri_cal/property_value.rb', line 128

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:



89
90
91
# File 'lib/ri_cal/property_value.rb', line 89

def equality_value #:nodoc:
  value
end

#find_timezone(timezone_identifier) ⇒ Object

:nodoc:



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

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:



97
98
99
100
101
102
103
104
# File 'lib/ri_cal/property_value.rb', line 97

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



112
113
114
# File 'lib/ri_cal/property_value.rb', line 112

def ruby_value
  self.value
end

#to_options_hashObject

:nodoc:



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

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

#to_ri_cal_property_valueObject

:nodoc:



116
117
118
# File 'lib/ri_cal/property_value.rb', line 116

def to_ri_cal_property_value #:nodoc:
  self
end

#to_sObject

Return a string representing the receiver in RFC 2445 format



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

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

#tz_info_source?Boolean

:nodoc:

Returns:

  • (Boolean)


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

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

#validate_value(options) ⇒ Object

:nodoc:



28
29
30
31
# File 'lib/ri_cal/property_value.rb', line 28

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:



93
94
95
# File 'lib/ri_cal/property_value.rb', line 93

def visible_params # :nodoc:
  params
end