Class: Icalendar::Values::Recur

Inherits:
Icalendar::Value show all
Defined in:
lib/icalendar/values/recur.rb

Constant Summary collapse

NUM_LIST =
'\d{1,2}(?:,\d{1,2})*'
DAYNAME =
'SU|MO|TU|WE|TH|FR|SA'
WEEKDAY =
"(?:[+-]?\\d{1,2})?(?:#{DAYNAME})"
MONTHDAY =
'[+-]?\d{1,2}'
YEARDAY =
'[+-]?\d{1,3}'

Instance Attribute Summary

Attributes inherited from Icalendar::Value

#ical_params

Instance Method Summary collapse

Methods inherited from Icalendar::Value

#ical_param, #params_ical, #to_ical, #value, value_type, #value_type

Constructor Details

#initialize(value, params = {}) ⇒ Recur


13
14
15
16
17
18
19
# File 'lib/icalendar/values/recur.rb', line 13

def initialize(value, params = {})
  if value.is_a? Icalendar::Values::Recur
    super value.value, params
  else
    super OpenStruct.new(parse_fields value), params
  end
end

Instance Method Details

#valid?Boolean


21
22
23
24
25
# File 'lib/icalendar/values/recur.rb', line 21

def valid?
  return false if frequency.nil?
  return false if !self.until.nil? && !count.nil?
  true
end

#value_icalObject


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/icalendar/values/recur.rb', line 27

def value_ical
  builder = ["FREQ=#{frequency}"]
  builder << "UNTIL=#{self.until}" unless self.until.nil?
  builder << "COUNT=#{count}" unless count.nil?
  builder << "INTERVAL=#{interval}" unless interval.nil?
  builder << "BYSECOND=#{by_second.join ','}" unless by_second.nil?
  builder << "BYMINUTE=#{by_minute.join ','}" unless by_minute.nil?
  builder << "BYHOUR=#{by_hour.join ','}" unless by_hour.nil?
  builder << "BYDAY=#{by_day.join ','}" unless by_day.nil?
  builder << "BYMONTHDAY=#{by_month_day.join ','}" unless by_month_day.nil?
  builder << "BYYEARDAY=#{by_year_day.join ','}" unless by_year_day.nil?
  builder << "BYWEEKNO=#{by_week_number.join ','}" unless by_week_number.nil?
  builder << "BYMONTH=#{by_month.join ','}" unless by_month.nil?
  builder << "BYSETPOS=#{by_set_position.join ','}" unless by_set_position.nil?
  builder << "WKST=#{week_start}" unless week_start.nil?
  builder.join ';'
end