class Tilia::VObject::Property::ICalendar::Recur

Recur property.

This object represents RECUR properties. These values are just used for RRULE and the now deprecated EXRULE.

The RRULE property may look something like this:

RRULE:FREQ=MONTHLY;BYDAY=1,2,3;BYHOUR=5.

This property exposes this as a key=>value array that is accessible using getParts, and may be set using setParts.

Protected Class Methods

string_to_array(value) click to toggle source

Parses an RRULE value string, and turns it into a struct-ish array.

@param [String] value @return [array]

# File lib/tilia/v_object/property/i_calendar/recur.rb, line 144
def self.string_to_array(value)
  value = value.upcase
  new_value = {}
  value.split(';').each do |part|
    # Skipping empty parts.
    next if part.blank?

    (part_name, part_value) = part.split('=')

    # The value itself had multiple values..
    part_value = part_value.split(',') if part_value.index(',')

    new_value[part_name] = part_value
  end

  new_value
end

Public Instance Methods

json_value() click to toggle source

Returns the value, in the format it should be encoded for json.

This method must always return an array.

@return [array]

# File lib/tilia/v_object/property/i_calendar/recur.rb, line 117
def json_value
  values = {}
  parts.each do |k, v|
    values[k.downcase] = v
  end
  [values]
end
parts() click to toggle source

Returns a multi-valued property.

This method always returns an array, if there was only a single value, it will still be wrapped in an array.

@return [array]

# File lib/tilia/v_object/property/i_calendar/recur.rb, line 80
def parts
  @value
end
parts=(parts) click to toggle source

Sets a multi-valued property.

@param [array] parts @return [void]

# File lib/tilia/v_object/property/i_calendar/recur.rb, line 70
def parts=(parts)
  self.value = parts
end
raw_mime_dir_value() click to toggle source

Returns a raw mime-dir representation of the value.

@return [String]

# File lib/tilia/v_object/property/i_calendar/recur.rb, line 98
def raw_mime_dir_value
  value
end
raw_mime_dir_value=(val) click to toggle source

Sets a raw value coming from a mimedir (iCalendar/vCard) file.

This has been 'unfolded', so only 1 line will be passed. Unescaping is not yet done, but parameters are not included.

@param [String] val @return [void]

# File lib/tilia/v_object/property/i_calendar/recur.rb, line 91
def raw_mime_dir_value=(val)
  self.value = val
end
value() click to toggle source

Returns the current value.

This method will always return a singular value. If this was a multi-value object, some decision will be made first on how to represent it as a string.

To get the correct multi-value version, use getParts.

@return [String]

# File lib/tilia/v_object/property/i_calendar/recur.rb, line 58
def value
  out = []
  @value.each do |key, value|
    out << "#{key}=#{value.is_a?(Array) ? value.join(',') : value}"
  end
  out.join(';').upcase
end
value=(value) click to toggle source

Updates the current value.

This may be either a single, or multiple strings in an array.

@param [String|array] value

@return [void]

# File lib/tilia/v_object/property/i_calendar/recur.rb, line 24
def value=(value)
  if value.is_a?(Hash)
    new_val = {}
    value.each do |k, v|
      if v.is_a?(String)
        v = v.upcase

        # The value had multiple sub-values
        v = v.split(',') if v.index(',')
        v = v.gsub(/[:\-]/, '') if k == 'until'
      else
        v = v.map { |val| val.is_a?(String) ? val.upcase : val }
      end

      new_val[k.upcase] = v
    end

    @value = new_val
  elsif value.is_a?(String)
    @value = self.class.string_to_array(value)
  else
    fail ArgumentError, 'You must either pass a string, or a key=>value array'
  end
end
value_type() click to toggle source

Returns the type of value.

This corresponds to the VALUE= parameter. Every property also has a 'default' valueType.

@return [String]

# File lib/tilia/v_object/property/i_calendar/recur.rb, line 108
def value_type
  'RECUR'
end

Protected Instance Methods

xml_serialize_value(writer) click to toggle source

This method serializes only the value of a property. This is used to create xCard or xCal documents.

@param [XmlWriter] writer XML writer. @return [void]

# File lib/tilia/v_object/property/i_calendar/recur.rb, line 132
def xml_serialize_value(writer)
  value_type = self.value_type.downcase

  json_value.each do |value|
    writer.write_element(value_type, value)
  end
end