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)



17
18
19
20
# File 'lib/rrule.rb', line 17

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



241
242
243
# File 'lib/rrule.rb', line 241

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

Instance Method Details

#countObject



42
43
44
# File 'lib/rrule.rb', line 42

def count
  @rrule.getCount
end

#count=(new_count) ⇒ Object

Options

new_count

number of count



48
49
50
51
# File 'lib/rrule.rb', line 48

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



191
192
193
194
195
# File 'lib/rrule.rb', line 191

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



203
204
205
206
# File 'lib/rrule.rb', line 203

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



34
35
36
37
38
39
40
# File 'lib/rrule.rb', line 34

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



149
150
151
# File 'lib/rrule.rb', line 149

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



158
159
160
161
# File 'lib/rrule.rb', line 158

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

#hoursObject



53
54
55
# File 'lib/rrule.rb', line 53

def hours
  @rrule.getByHour.to_a
end

#hours=(new_hours = []) ⇒ Object

Options

new_hours

array of numbers (0..23)



59
60
61
62
# File 'lib/rrule.rb', line 59

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

#intervalObject



163
164
165
# File 'lib/rrule.rb', line 163

def interval
  @rrule.getInterval
end

#interval=(new_interval) ⇒ Object



167
168
169
170
# File 'lib/rrule.rb', line 167

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

#mdaysObject

Gets the days of month



87
88
89
# File 'lib/rrule.rb', line 87

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)



95
96
97
98
# File 'lib/rrule.rb', line 95

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

#minutesObject



64
65
66
# File 'lib/rrule.rb', line 64

def minutes
  @rrule.getByMinute.to_a
end

#minutes=(new_minutes = []) ⇒ Object

Options

new_minutes

array of numbers (0..59)



70
71
72
73
# File 'lib/rrule.rb', line 70

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

#monthsObject



75
76
77
# File 'lib/rrule.rb', line 75

def months
  @rrule.getByMonth.to_a
end

#months=(new_months = []) ⇒ Object

Options

new_months

array of numbers (1..12)



81
82
83
84
# File 'lib/rrule.rb', line 81

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



174
175
176
# File 'lib/rrule.rb', line 174

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’



183
184
185
186
# File 'lib/rrule.rb', line 183

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

#secondsObject



100
101
102
# File 'lib/rrule.rb', line 100

def seconds
  @rrule.getBySecond.to_a
end

#seconds=(new_seconds = []) ⇒ Object

Options

new_seconds

array of days of month (0..59)



106
107
108
109
# File 'lib/rrule.rb', line 106

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

#setposObject



111
112
113
# File 'lib/rrule.rb', line 111

def setpos
  @rrule.getBySetPos.to_a
end

#setpos=(new_setpos = []) ⇒ Object



115
116
117
118
# File 'lib/rrule.rb', line 115

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

#to_icalObject

Returns the unfolded RFC 2445 content line.



28
29
30
# File 'lib/rrule.rb', line 28

def to_ical
  @rrule.toIcal
end

#to_javaObject

Returns the underlying Java object



23
24
25
# File 'lib/rrule.rb', line 23

def to_java
  @rrule
end

#untilObject

Gets the end date



225
226
227
228
# File 'lib/rrule.rb', line 225

def until
  d = @rrule.getUntil
  d ? JTime.local(d.year, d.month, d.day, d.hour, d.minute, d.second) : nil
end

#until=(new_date) ⇒ Object

Sets the end date

Options

new_date

JTime object



234
235
236
237
238
# File 'lib/rrule.rb', line 234

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)



209
210
211
212
# File 'lib/rrule.rb', line 209

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’



218
219
220
221
222
# File 'lib/rrule.rb', line 218

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

#weeknumsObject



120
121
122
# File 'lib/rrule.rb', line 120

def weeknums
  @rrule.getByWeekNo.to_a
end

#weeknums=(new_weeknums = []) ⇒ Object

Sets the numbers of week

Options

new_weeknums

array of weeks (1..52)



128
129
130
131
# File 'lib/rrule.rb', line 128

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

#ydaysObject

Gets the day of year



134
135
136
# File 'lib/rrule.rb', line 134

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)



142
143
144
145
# File 'lib/rrule.rb', line 142

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