Class: Tilia::VObject::Property::ICalendar::Recur

Inherits:
Tilia::VObject::Property show all
Defined in:
lib/tilia/v_object/property/i_calendar/recur.rb

Overview

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.

Constant Summary

Constants inherited from Node

Node::PROFILE_CALDAV, Node::PROFILE_CARDDAV, Node::REPAIR

Instance Attribute Summary

Attributes inherited from Tilia::VObject::Property

#delimiter, #group, #name, #parameters

Attributes inherited from Node

#iterator, #parent

Instance Method Summary collapse

Methods inherited from Tilia::VObject::Property

#==, #[], #[]=, #add, #delete, #destroy, #initialize, #initialize_copy, #json_serialize, #json_value=, #key?, #serialize, #to_s, #validate, #xml_serialize, #xml_value=

Methods inherited from Node

#==, #[], #[]=, #delete, #destroy, #each, #initialize, #json_serialize, #key?, #serialize, #size, #validate, #xml_serialize

Constructor Details

This class inherits a constructor from Tilia::VObject::Property

Instance Method Details

#json_valuearray

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

This method must always return an array.

Returns:

  • (array)


117
118
119
120
121
122
123
# 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

#partsarray

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.

Returns:

  • (array)


80
81
82
# File 'lib/tilia/v_object/property/i_calendar/recur.rb', line 80

def parts
  @value
end

#parts=(parts) ⇒ void

This method returns an undefined value.

Sets a multi-valued property.

Parameters:

  • parts (array)


70
71
72
# File 'lib/tilia/v_object/property/i_calendar/recur.rb', line 70

def parts=(parts)
  self.value = parts
end

#raw_mime_dir_valueString

Returns a raw mime-dir representation of the value.

Returns:

  • (String)


98
99
100
# File 'lib/tilia/v_object/property/i_calendar/recur.rb', line 98

def raw_mime_dir_value
  value
end

#raw_mime_dir_value=(val) ⇒ void

This method returns an undefined value.

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.

Parameters:

  • val (String)


91
92
93
# File 'lib/tilia/v_object/property/i_calendar/recur.rb', line 91

def raw_mime_dir_value=(val)
  self.value = val
end

#valueString

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.

Returns:

  • (String)


58
59
60
61
62
63
64
# 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) ⇒ void

This method returns an undefined value.

Updates the current value.

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

Parameters:

  • value (String|array)


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# 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_typeString

Returns the type of value.

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

Returns:

  • (String)


108
109
110
# File 'lib/tilia/v_object/property/i_calendar/recur.rb', line 108

def value_type
  'RECUR'
end