Class: RiCal::PropertyValue::RecurrenceRule

Inherits:
RiCal::PropertyValue show all
Includes:
EnumerationSupportMethods, InitializationMethods, Validations
Defined in:
lib/ri_cal/property_value/recurrence_rule.rb,
lib/ri_cal/property_value/recurrence_rule/enumerator.rb,
lib/ri_cal/property_value/recurrence_rule/validations.rb,
lib/ri_cal/property_value/recurrence_rule/numbered_span.rb,
lib/ri_cal/property_value/recurrence_rule/recurring_day.rb,
lib/ri_cal/property_value/recurrence_rule/time_manipulation.rb,
lib/ri_cal/property_value/recurrence_rule/recurring_year_day.rb,
lib/ri_cal/property_value/recurrence_rule/recurring_month_day.rb,
lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/recurring_numbered_week.rb,
lib/ri_cal/property_value/recurrence_rule/negative_setpos_enumerator.rb,
lib/ri_cal/property_value/recurrence_rule/enumeration_support_methods.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/list_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/daily_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_day_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/hourly_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/weekly_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/yearly_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_hour_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/monthly_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_month_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/minutely_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/secondly_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_minute_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_second_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_weekno_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/frequency_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_yearday_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_monthday_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/null_sub_cycle_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_numbered_day_incrementer.rb

Overview

RiCal::PropertyValue::RecurrenceRule represents an icalendar Recurrence Rule property value which is defined in rfc 2445 section 4.3.10 pp 40-45

Defined Under Namespace

Modules: EnumerationSupportMethods, InitializationMethods, TimeManipulation, Validations Classes: Enumerator, NegativeSetposEnumerator, NumberedSpan, OccurrenceIncrementer, RecurringDay, RecurringMonthDay, RecurringNumberedWeek, RecurringYearDay

Instance Attribute Summary collapse

Attributes included from InitializationMethods

#by_day_scope

Attributes inherited from RiCal::PropertyValue

#params, #timezone_finder

Class Method Summary collapse

Instance Method Summary collapse

Methods included from EnumerationSupportMethods

#adjust_start, #by_rule_list, #enumerator, #exhausted?, #in_same_set?, #incrementer_from_start_time

Methods included from InitializationMethods

#add_byrule_strings_to_options_hash, #add_to_options_hash, #by_list, #byday=, #byhour=, #byminute=, #bymonth=, #bymonthday=, #bysecond=, #bysetpos=, #byweekno=, #byyearday=, #calc_by_day_scope, #init_by_lists, #initialize_from_value_part, #to_options_hash

Methods included from Validations

#errors, #reset_errors, #valid?, #validate, #validate_byday_list, #validate_bymonthday_list, #validate_bysetpos, #validate_byweekno_list, #validate_byyearday_list, #validate_freq, #validate_int_by_list, #validate_interval, #validate_termination, #validate_wkst

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, #ruby_value, #to_options_hash, #to_ri_cal_property_value, #to_s, #tz_info_source?, #validate_value, #visible_params

Constructor Details

#initialize(parent, value_hash) ⇒ RecurrenceRule

:nodoc:



21
22
23
24
25
26
# File 'lib/ri_cal/property_value/recurrence_rule.rb', line 21

def initialize(parent, value_hash) # :nodoc:
  @by_list_hash = {}
  super
  init_by_lists
  @by_list_hash = nil
end

Instance Attribute Details

#countObject

The integer count value of the receiver, or nil



42
43
44
# File 'lib/ri_cal/property_value/recurrence_rule.rb', line 42

def count
  @count
end

#untilObject

The DATE-TIME value of until limit of the receiver, or nil



44
45
46
# File 'lib/ri_cal/property_value/recurrence_rule.rb', line 44

def until
  @until
end

Class Method Details

.convert(parent, value) ⇒ Object

:nodoc:



28
29
30
31
32
33
34
35
# File 'lib/ri_cal/property_value/recurrence_rule.rb', line 28

def self.convert(parent, value) #:nodoc:
  if String === value
    result = new(parent, :value => value)
  else
    result = new(parent, value)
  end
  result
end

Instance Method Details

#bounded?Boolean

Predicate to determine if the receiver generates a bounded or infinite set of occurrences

Returns:

  • (Boolean)


147
148
149
# File 'lib/ri_cal/property_value/recurrence_rule.rb', line 147

def bounded?
  @count || @until
end

#freqObject

return the frequency of the rule which will be a string



66
67
68
# File 'lib/ri_cal/property_value/recurrence_rule.rb', line 66

def freq
  @freq.upcase
end

#freq=(freq_value) ⇒ Object

Set the frequency of the recurrence rule

freq_value

a String which should be in %w[SECONDLY MINUTELY HOURLY DAILY WEEKLY MONTHLY YEARLY]

This method resets the receivers list of errors



60
61
62
63
# File 'lib/ri_cal/property_value/recurrence_rule.rb', line 60

def freq=(freq_value)
  reset_errors
  @freq = freq_value
end

#intervalObject

return the INTERVAL parameter of the recurrence rule This returns an Integer



114
115
116
# File 'lib/ri_cal/property_value/recurrence_rule.rb', line 114

def interval
  @interval ||= 1
end

#interval=(interval_value) ⇒ Object

Set the INTERVAL parameter of the recurrence rule

interval_value

an Integer

This method resets the receivers list of errors



123
124
125
126
# File 'lib/ri_cal/property_value/recurrence_rule.rb', line 123

def interval=(interval_value)
  reset_errors
  @interval = interval_value
end

#to_icalObject

Return a string containing the RFC 2445 representation of the recurrence rule



133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/ri_cal/property_value/recurrence_rule.rb', line 133

def to_ical
  result = ["FREQ=#{freq}"]
  result << "INTERVAL=#{interval}" unless interval == 1
  result << "COUNT=#{count}" if count
  result << "UNTIL=#{self.until.value}" if self.until
  %w{bysecond byminute byhour byday bymonthday byyearday byweekno bymonth bysetpos}.each do |by_part|
    val = by_list[by_part.to_sym]
    result << "#{by_part.upcase}=#{[val].flatten.join(',')}" if val
  end
  result << "WKST=#{wkst}" unless wkst == "MO"
  result.join(";")
end

#valueObject

:nodoc:



128
129
130
# File 'lib/ri_cal/property_value/recurrence_rule.rb', line 128

def value #:nodoc:
  @value || to_ical
end

#value=(string) ⇒ Object

:nodoc:



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

def value=(string) # :nodoc:
  if string
    @value = string
    dup_hash = {}
    string.split(";").each do |value_part|
      initialize_from_value_part(value_part, dup_hash)
    end
  end
end

#wkstObject

return the starting week day for the recurrence rule, which for a valid instance will be one of “SU”, “MO”, “TU”, “WE”, “TH”, “FR”, or “SA”



72
73
74
# File 'lib/ri_cal/property_value/recurrence_rule.rb', line 72

def wkst
  @wkst || 'MO'
end

#wkst=(value) ⇒ Object

Set the starting week day for the recurrence rule, which should be one of “SU”, “MO”, “TU”, “WE”, “TH”, “FR”, or “SA” for the instance to be valid. The parameter is however case-insensitive.

This method resets the receivers list of errors



85
86
87
88
89
# File 'lib/ri_cal/property_value/recurrence_rule.rb', line 85

def wkst=(value)
  reset_errors
  @wkst = value
  @wkst_day = nil
end

#wkst_dayObject

:nodoc:



76
77
78
# File 'lib/ri_cal/property_value/recurrence_rule.rb', line 76

def wkst_day # :nodoc:
  @wkst_day ||= (%w{SU MO TU WE TH FR SA}.index(wkst) || 1)
end