Class: RiCal::PropertyValue::OccurrenceList

Inherits:
Array show all
Defined in:
lib/ri_cal/property_value/occurrence_list.rb

Overview

OccurrenceList is used to represent the value of an RDATE or EXDATE property.

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

Defined Under Namespace

Classes: Enumerator

Instance Attribute Summary collapse

Attributes inherited from RiCal::PropertyValue

#params, #timezone_finder

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Array

#value=

Methods inherited from RiCal::PropertyValue

#==, #add_date_times_to, date_or_date_time, date_or_date_time_or_period, #default_tzid, #enumerator, #equality_value, #find_timezone, #for_parent, if_valid_string, #parms_string, #to_options_hash, #to_ri_cal_property_value, #to_s, #tz_info_source?, #validate_value

Constructor Details

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

:nodoc:



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

def initialize(timezone_finder, options={}) # :nodoc:
  super
  validate_elements
end

Instance Attribute Details

#tzidObject

:nodoc:



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

def tzid
  @tzid
end

Class Method Details

.convert(timezone_finder, *ruby_objects) ⇒ Object

:nodoc:



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

def self.convert(timezone_finder, *ruby_objects) # :nodoc:
  # ruby_objects = [ruby_objects] unless Array === ruby_objects
  source_elements = ruby_objects.inject([]) { |se, element|
    if String === element
      element.split(",").each {|str| se << str}
    else
      se << element
    end
    se
    }        
  new(timezone_finder, :source_elements => source_elements )
end

Instance Method Details

#has_local_timezone?Boolean

:nodoc:

Returns:

  • (Boolean)


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

def has_local_timezone? # :nodoc:
  tzid && tzid != 'UTC'
end

#ruby_valueObject

Return an array of the occurrences within the list



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

def ruby_value
  @elements.map {|prop| prop.ruby_value}
end

#tzid_conflict(element_tzid) ⇒ Object

:nodoc:



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

def tzid_conflict(element_tzid) # :nodoc:
  element_tzid && tzid != element_tzid
end

#tzid_from_source_elementsObject

:nodoc:



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

def tzid_from_source_elements # :nodoc:
  if @source_elements && String === (first_source = @source_elements.first)
    probe = first_source.to_ri_cal_occurrence_list_value rescue nil
    unless probe
      return @source_elements.shift
    end
  end
  nil
end

#validate_elementsObject

:nodoc:



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/ri_cal/property_value/occurrence_list.rb', line 75

def validate_elements # :nodoc:
  if @source_elements
    self.tzid = tzid_from_source_elements
     @elements = values_to_elements(@source_elements)
    @value = @elements.map {|prop| prop.value}
  else
    @elements = values_to_elements(@value)
    self.tzid = params['TZID']
  end
  # if the tzid wasn't set by the parameters
  self.tzid ||= @elements.map {|element| element.tzid}.find {|id| id}
  @elements.each do |element|
    raise InvalidPropertyValue.new("Mixed timezones are not allowed in an occurrence list") if tzid_conflict(element.tzid)
    element.tzid = tzid
  end
end

#valueObject

:nodoc:



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

def value # :nodoc:
  @elements.map {|element| element.value}.join(",")
end

#values_to_elements(values) ⇒ Object

:nodoc:



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

def values_to_elements(values) # :nodoc:
  values.map {|val| val.to_ri_cal_occurrence_list_value(self)}
end

#visible_paramsObject

:nodoc:



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

def visible_params # :nodoc:
  result = params.dup
  if has_local_timezone?
    result['TZID'] = tzid
  else
    result.delete('TZID')
  end
  result
end