Class: RRule

Inherits:
Object
  • Object
show all
Defined in:
lib/rrule.rb

Constant Summary collapse

RRULE =
'RRULE'
EXRULE =
'EXRULE'
VEVENT =
'VEVENT'

Instance Method Summary collapse

Constructor Details

#initialize(ical_string = nil) ⇒ RRule

Initializes a Recurrence Rule with optionally an iCal string

Options

ical_string

Optional. The iCal string for the recurrent rule. The string must specify the rule type (RRULE, EXRULE or VEVENT)



19
20
21
22
# File 'lib/rrule.rb', line 19

def initialize(ical_string=nil)
  @rrule = ical_string ? JRRule.new(ical_string) : JRRule.new
  self
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(key, *params) ⇒ Object

We should consider getting rid of this or implement this using meta-programming



250
251
252
# File 'lib/rrule.rb', line 250

def method_missing(key, *params)
  @rrule.send(key, *params)
end

Instance Method Details

#countObject



44
45
46
# File 'lib/rrule.rb', line 44

def count
  @rrule.getCount
end

#count=(new_count) ⇒ Object

Options

new_count

number of count



50
51
52
53
# File 'lib/rrule.rb', line 50

def count=(new_count)
  @rrule.setCount(new_count)
  self
end

#daysObject

Gets the WeekdayNums for the recurrence rule WeekdayNum is an object which specifies the week of year and the day of week



193
194
195
196
197
# File 'lib/rrule.rb', line 193

def days
  @rrule.getByDay.to_a.map do |d|
    WeekdayNum.new(d)
  end
end

#days=(new_days) ⇒ Object

Sets the WeekdayNums for the recurrence rule WeekdayNum is an object which specifies the week of year and the day of week

Options

new_days

Array of WeekdayNums



205
206
207
208
# File 'lib/rrule.rb', line 205

def days=(new_days)
  @rrule.setByDay(new_days.map {|d| d.to_java})
  self
end

#ext_paramsObject

Returns a hash map of any extension parameters such as the X-FOO=BAR in RRULE;X-FOO=BAR



36
37
38
39
40
41
42
# File 'lib/rrule.rb', line 36

def ext_params
  h = {}
  @rrule.getExtParams.to_a.each do |p|
    h[p[0]] = p[1]
  end
  h
end

#frequencyObject

Gets the recurrence frequency, return type is defined in “com.google.ical.values.Frequency”, such as Frequency::MONTHLY



151
152
153
# File 'lib/rrule.rb', line 151

def frequency
  @rrule.getFreq
end

#frequency=(freq) ⇒ Object

Sets the recurrence frequency

Options

freq

defined in com.google.ical.values.Frequency, such as Frequency::MONTHLY or Frequency::DAILY



160
161
162
163
# File 'lib/rrule.rb', line 160

def frequency=(freq)
  @rrule.setFreq(freq)
  self
end

#hoursObject



55
56
57
# File 'lib/rrule.rb', line 55

def hours
  @rrule.getByHour.to_a
end

#hours=(new_hours = []) ⇒ Object

Options

new_hours

array of numbers (0..23)



61
62
63
64
# File 'lib/rrule.rb', line 61

def hours=(new_hours=[])
  @rrule.setByHour(new_hours.to_java(:int))
  self
end

#intervalObject



165
166
167
# File 'lib/rrule.rb', line 165

def interval
  @rrule.getInterval
end

#interval=(new_interval) ⇒ Object



169
170
171
172
# File 'lib/rrule.rb', line 169

def interval=(new_interval)
  @rrule.setInterval(new_interval)
  self
end

#mdaysObject

Gets the days of month



89
90
91
# File 'lib/rrule.rb', line 89

def mdays
  @rrule.getByMonthDay.to_a
end

#mdays=(new_mdays = []) ⇒ Object

Sets the days of month

Options

new_mdays

array of days of month (1..31)



97
98
99
100
# File 'lib/rrule.rb', line 97

def mdays=(new_mdays=[])
  @rrule.setByMonthDay(new_mdays.to_java(:int))
  self
end

#minutesObject



66
67
68
# File 'lib/rrule.rb', line 66

def minutes
  @rrule.getByMinute.to_a
end

#minutes=(new_minutes = []) ⇒ Object

Options

new_minutes

array of numbers (0..59)



72
73
74
75
# File 'lib/rrule.rb', line 72

def minutes=(new_minutes=[])
  @rrule.setByMinute(new_minutes.to_java(:int))
  self
end

#monthsObject



77
78
79
# File 'lib/rrule.rb', line 77

def months
  @rrule.getByMonth.to_a
end

#months=(new_months = []) ⇒ Object

Options

new_months

array of numbers (1..12)



83
84
85
86
# File 'lib/rrule.rb', line 83

def months=(new_months=[])
  @rrule.setByMonth(new_months.to_java(:int))
  self
end

#nameObject

Returns the type of the recurrence rule such as RRULE, EXRULE, or VEVENT



176
177
178
# File 'lib/rrule.rb', line 176

def name
  @rrule.getName
end

#name=(new_name) ⇒ Object

Sets the type of the recurrence rule such as RRULE, EXRULE, or VEVENT

Options

new_name

‘RRULE’, ‘EXRULE’, or ‘VEVENT’



185
186
187
188
# File 'lib/rrule.rb', line 185

def name=(new_name)
  @rrule.setName(new_name)
  self
end

#secondsObject



102
103
104
# File 'lib/rrule.rb', line 102

def seconds
  @rrule.getBySecond.to_a
end

#seconds=(new_seconds = []) ⇒ Object

Options

new_seconds

array of days of month (0..59)



108
109
110
111
# File 'lib/rrule.rb', line 108

def seconds=(new_seconds=[])
  @rrule.setBySecond(new_seconds.to_java(:int))
  self
end

#setposObject



113
114
115
# File 'lib/rrule.rb', line 113

def setpos
  @rrule.getBySetPos.to_a
end

#setpos=(new_setpos = []) ⇒ Object



117
118
119
120
# File 'lib/rrule.rb', line 117

def setpos=(new_setpos=[])
  @rrule.setByPos(new_setpos.to_java(:int))
  self
end

#to_icalObject

Returns the unfolded RFC 2445 content line.



30
31
32
# File 'lib/rrule.rb', line 30

def to_ical
  @rrule.toIcal
end

#to_javaObject

Returns the underlying Java object



25
26
27
# File 'lib/rrule.rb', line 25

def to_java
  @rrule
end

#untilObject

Gets the end date, assume it is UTC for now



227
228
229
230
231
232
233
234
235
236
237
# File 'lib/rrule.rb', line 227

def until
  d = @rrule.getUntil
  case d
  when DateTimeValue
    JTime.from_date_time_value(d)
  when DateValue
    JTime.from_date_value(d)
  else
    nil
  end
end

#until=(new_date) ⇒ Object

Sets the end date

Options

new_date

JTime object



243
244
245
246
247
# File 'lib/rrule.rb', line 243

def until=(new_date)
  d = com.google.ical.values.DateTimeValueImpl.new(new_date.year, new_date.month, new_date.day, new_date.hour, new_date.min, new_date.sec)
  @rrule.setUntil(d)
  self
end

#wdaystartObject

Gets the starting day of the week (0-6)



211
212
213
214
# File 'lib/rrule.rb', line 211

def wdaystart
  weekday = @rrule.getWkSt
  Weekday::MAP[weekday]
end

#wdaystart=(wday) ⇒ Object

Sets the starting day of the week (0-6, Mon-Sun, Mo-Su)

Options

wday

0-6, ‘Mon’ - ‘Sun’, or ‘Mo’ - ‘Su’



220
221
222
223
224
# File 'lib/rrule.rb', line 220

def wdaystart=(wday)
  wday = Weekday::MAP[wday.to_s.downcase]
  @rrule.setWkSt(wday)
  self
end

#weeknumsObject



122
123
124
# File 'lib/rrule.rb', line 122

def weeknums
  @rrule.getByWeekNo.to_a
end

#weeknums=(new_weeknums = []) ⇒ Object

Sets the numbers of week

Options

new_weeknums

array of weeks (1..52)



130
131
132
133
# File 'lib/rrule.rb', line 130

def weeknums=(new_weeknums=[])
  @rrule.setByWeekNo(new_weeknums.to_java(:int))
  self
end

#ydaysObject

Gets the day of year



136
137
138
# File 'lib/rrule.rb', line 136

def ydays
  @rrule.getByYearDay.to_a
end

#ydays=(new_ydays = []) ⇒ Object

Sets the day of year

Options

new_ydays

array of day of year (1..365)



144
145
146
147
# File 'lib/rrule.rb', line 144

def ydays=(new_ydays=[])
  @rrule.setByYearDay(new_ydays.to_java(:int))
  self
end