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

Modules: AdditiveMethods, TimeMachine, TimezoneSupport 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:



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

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}="
      send(setter, val)
    end
  end
end

Instance Attribute Details

#paramsObject

return a hash containing the parameters and values, if any



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

def params
  @params ||= {}
end

#timezone_finderObject (readonly)

:nodoc:



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

def timezone_finder
  @timezone_finder
end

#valueObject

Return the string value



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

def value
  @value
end

Class Method Details

.convert(parent, value) ⇒ Object

:nodoc:



56
57
58
# File 'lib/ri_cal/property_value.rb', line 56

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

.date_or_date_time(parent, separated_line) ⇒ Object

:nodoc:

Raises:

  • (Exception)


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

def self.date_or_date_time(parent, 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(parent, separated_line.merge(:params => parms))
  else
    PropertyValue::Date.new(parent, separated_line)
  end
end

.from_string(string) ⇒ Object

:nodoc:



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

def self.from_string(string) # :nodoc:
  new(nil, :value => string)
end

Instance Method Details

#==(o) ⇒ Object

Determine if another object is equivalent to the receiver.



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

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

#add_date_times_to(required_timezones) ⇒ Object

:nodoc:



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

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

#enumerator(component) ⇒ Object

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



69
70
71
# File 'lib/ri_cal/property_value/occurrence_list.rb', line 69

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

#equality_valueObject

:nodoc:



74
75
76
# File 'lib/ri_cal/property_value.rb', line 74

def equality_value #:nodoc:
  value
end

#for_parent(parent) ⇒ Object



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

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

#parms_stringObject

:nodoc:



82
83
84
85
86
87
88
89
# File 'lib/ri_cal/property_value.rb', line 82

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



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

def ruby_value
  self.value
end

#to_options_hashObject

:nodoc:



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

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

#to_ri_cal_property_valueObject

:nodoc:



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

def to_ri_cal_property_value #:nodoc:
  self
end

#to_sObject

Return a string representing the receiver in RFC 2445 format



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

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

#validate_value(options) ⇒ Object

:nodoc:



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

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:



78
79
80
# File 'lib/ri_cal/property_value.rb', line 78

def visible_params # :nodoc:
  params
end