Class: RiCal::PropertyValue::OccurrenceList
- Inherits:
-
Array
- Object
- RiCal::PropertyValue
- Array
- RiCal::PropertyValue::OccurrenceList
- Defined in:
- lib/ri_cal/property_value/occurrence_list.rb
Overview
OccurrenceList is used to represent the value of an RDATE or EXDATE property.
Defined Under Namespace
Classes: Enumerator
Instance Attribute Summary collapse
-
#tzid ⇒ Object
:nodoc:.
Attributes inherited from RiCal::PropertyValue
Class Method Summary collapse
Instance Method Summary collapse
-
#has_local_timezone? ⇒ Boolean
:nodoc:.
-
#initialize(timezone_finder, options = {}) ⇒ OccurrenceList
constructor
:nodoc:.
-
#ruby_value ⇒ Object
Return an array of the occurrences within the list.
-
#tzid_conflict(element_tzid) ⇒ Object
:nodoc:.
-
#tzid_from_source_elements ⇒ Object
:nodoc:.
-
#validate_elements ⇒ Object
:nodoc:.
-
#value ⇒ Object
:nodoc:.
-
#values_to_elements(values) ⇒ Object
:nodoc:.
-
#visible_params ⇒ Object
:nodoc:.
Methods inherited from Array
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:
37 38 39 40 |
# File 'lib/ri_cal/property_value/occurrence_list.rb', line 37 def initialize(timezone_finder, ={}) # :nodoc: super validate_elements end |
Instance Attribute Details
#tzid ⇒ Object
:nodoc:
5 6 7 |
# File 'lib/ri_cal/property_value/occurrence_list.rb', line 5 def tzid @tzid end |
Class Method Details
.convert(timezone_finder, *ruby_objects) ⇒ Object
:nodoc:
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ri_cal/property_value/occurrence_list.rb', line 42 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:
90 91 92 |
# File 'lib/ri_cal/property_value/occurrence_list.rb', line 90 def has_local_timezone? # :nodoc: tzid && tzid != 'UTC' end |
#ruby_value ⇒ Object
Return an array of the occurrences within the list
109 110 111 |
# File 'lib/ri_cal/property_value/occurrence_list.rb', line 109 def ruby_value @elements.map {|prop| prop.ruby_value} end |
#tzid_conflict(element_tzid) ⇒ Object
:nodoc:
69 70 71 |
# File 'lib/ri_cal/property_value/occurrence_list.rb', line 69 def tzid_conflict(element_tzid) # :nodoc: element_tzid && tzid != element_tzid end |
#tzid_from_source_elements ⇒ Object
:nodoc:
59 60 61 62 63 64 65 66 67 |
# File 'lib/ri_cal/property_value/occurrence_list.rb', line 59 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_elements ⇒ Object
:nodoc:
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/ri_cal/property_value/occurrence_list.rb', line 73 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 |
#value ⇒ Object
:nodoc:
104 105 106 |
# File 'lib/ri_cal/property_value/occurrence_list.rb', line 104 def value # :nodoc: @elements.map {|element| element.value}.join(",") end |
#values_to_elements(values) ⇒ Object
:nodoc:
55 56 57 |
# File 'lib/ri_cal/property_value/occurrence_list.rb', line 55 def values_to_elements(values) # :nodoc: values.map {|val| val.to_ri_cal_occurrence_list_value(self)} end |
#visible_params ⇒ Object
:nodoc:
94 95 96 97 98 99 100 101 102 |
# File 'lib/ri_cal/property_value/occurrence_list.rb', line 94 def visible_params # :nodoc: result = params.dup if has_local_timezone? result['TZID'] = tzid else result.delete('TZID') end result end |