jerryluk-jruby-rfc2445 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/recurrence_time.rb +58 -0
- data/lib/rfc2445.jar +0 -0
- data/lib/weekday.rb +23 -0
- data/lib/weekday_num.rb +36 -0
- metadata +5 -4
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'java'
|
2
|
+
require File.dirname(__FILE__) + '/rfc2445.jar'
|
3
|
+
|
4
|
+
class RecurrenceTime
|
5
|
+
include Enumerable
|
6
|
+
include_class('com.google.ical.compat.jodatime.DateTimeIteratorFactory')
|
7
|
+
|
8
|
+
# Initializes a RecurrenceTime objects which generates JTime based on
|
9
|
+
# recurrence rule
|
10
|
+
#
|
11
|
+
# ==== Options
|
12
|
+
# +rdata+:: it can be one of the following:
|
13
|
+
# 1. RRULE, EXRULE, RDATE, and EXDATE lines (RFC 2445 content strings)
|
14
|
+
# 2. RRule or RDateList object
|
15
|
+
# 3. Array of RRule and RDateList objects, which can be a combinations of
|
16
|
+
# RRULE and EXRULE
|
17
|
+
# +start_time+:: Optional. Start time of the recurrence time. The default is now
|
18
|
+
# +strict+:: Optional. Any failure to parse should result in a ParseException
|
19
|
+
# false causes bad content lines to be logged and ignored. Default is true
|
20
|
+
#
|
21
|
+
def initialize(rdata, start_time=JTime.new, strict=true)
|
22
|
+
rdata = rdata.to_ical if (rdata.kind_of? RRule or
|
23
|
+
rdata.kind_of? RDateList)
|
24
|
+
rdata = (rdata.map {|r| r.to_ical}).join("\n") if rdata.kind_of? Array
|
25
|
+
@iterator = DateTimeIteratorFactory.createDateTimeIterator(rdata,
|
26
|
+
start_time.to_java,
|
27
|
+
start_time.java_zone,
|
28
|
+
strict)
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
# Returns a JTime for the instance of next recurrence time
|
33
|
+
def next
|
34
|
+
@iterator.hasNext ? JTime.new(@iterator.next) : nil
|
35
|
+
end
|
36
|
+
|
37
|
+
# Skips all dates in the series before the given date.
|
38
|
+
#
|
39
|
+
# ==== Options
|
40
|
+
# +new_start_time+:: JTime which the iterator is advanced to.
|
41
|
+
#
|
42
|
+
def advance_to(new_start_time)
|
43
|
+
@iterator.advanceTo(new_start_time.to_java)
|
44
|
+
self
|
45
|
+
end
|
46
|
+
|
47
|
+
def has_next?
|
48
|
+
@iterator.hasNext
|
49
|
+
end
|
50
|
+
|
51
|
+
def to_java
|
52
|
+
@iterator
|
53
|
+
end
|
54
|
+
|
55
|
+
def each
|
56
|
+
yield self.next until self.has_next? == false
|
57
|
+
end
|
58
|
+
end
|
data/lib/rfc2445.jar
ADDED
Binary file
|
data/lib/weekday.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'java'
|
2
|
+
require File.dirname(__FILE__) + '/rfc2445.jar'
|
3
|
+
|
4
|
+
class Weekday
|
5
|
+
include_class('com.google.ical.values.Weekday') {|package,name| "J#{name}" }
|
6
|
+
MAP = {
|
7
|
+
'0' => JWeekday::SU, 'sun' => JWeekday::SU, 'su' => JWeekday::SU,
|
8
|
+
'1' => JWeekday::MO, 'mon' => JWeekday::MO, 'mo' => JWeekday::MO,
|
9
|
+
'2' => JWeekday::TU, 'tue' => JWeekday::TU, 'tu' => JWeekday::TU,
|
10
|
+
'3' => JWeekday::WE, 'wed' => JWeekday::WE, 'we' => JWeekday::WE,
|
11
|
+
'4' => JWeekday::TH, 'thu' => JWeekday::TH, 'th' => JWeekday::TH,
|
12
|
+
'5' => JWeekday::FR, 'fri' => JWeekday::FR, 'fr' => JWeekday::FR,
|
13
|
+
'6' => JWeekday::SA, 'sat' => JWeekday::SA, 'sa' => JWeekday::SA,
|
14
|
+
JWeekday::SU => 0,
|
15
|
+
JWeekday::MO => 1,
|
16
|
+
JWeekday::TU => 2,
|
17
|
+
JWeekday::WE => 3,
|
18
|
+
JWeekday::TH => 4,
|
19
|
+
JWeekday::FR => 5,
|
20
|
+
JWeekday::SA => 6,
|
21
|
+
}
|
22
|
+
|
23
|
+
end
|
data/lib/weekday_num.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'java'
|
2
|
+
require File.dirname(__FILE__) + '/rfc2445.jar'
|
3
|
+
|
4
|
+
class WeekdayNum
|
5
|
+
include_class('com.google.ical.values.WeekdayNum'){|package,name| "J#{name}" }
|
6
|
+
|
7
|
+
# Initializes a WeekdayNum objects.
|
8
|
+
# It accepts a Java WeekdayNum object (com.google.ical.values.WeekdayNum) or
|
9
|
+
# the number of the week and the day of the week
|
10
|
+
def initialize(*args)
|
11
|
+
if args.size == 1
|
12
|
+
@weekdaynum = args[0]
|
13
|
+
elsif args.size == 2
|
14
|
+
num = args[0]
|
15
|
+
wday = args[1]
|
16
|
+
@weekdaynum = JWeekdayNum.new(num, Weekday::MAP[wday.to_s.downcase])
|
17
|
+
end
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_ical
|
22
|
+
@weekdaynum.toIcal
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_s
|
26
|
+
@weekdaynum.toString
|
27
|
+
end
|
28
|
+
|
29
|
+
def ==(weekdaynum)
|
30
|
+
@weekdaynum.equals(weekdaynum.to_java)
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_java
|
34
|
+
@weekdaynum
|
35
|
+
end
|
36
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jerryluk-jruby-rfc2445
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jerry Luk
|
@@ -27,11 +27,12 @@ files:
|
|
27
27
|
- lib/ical_parse_util.jar
|
28
28
|
- lib/jtime.rb
|
29
29
|
- lib/rdate_list.rb
|
30
|
-
- lib/recurrence_time.
|
30
|
+
- lib/recurrence_time.rb
|
31
31
|
- lib/rfc2445.rb
|
32
|
+
- lib/rfc2445.jar
|
32
33
|
- lib/rrule.rb
|
33
|
-
- weekday.rb
|
34
|
-
- weekday_num.rb
|
34
|
+
- lib/weekday.rb
|
35
|
+
- lib/weekday_num.rb
|
35
36
|
- spec/rfc2445_spec.rb
|
36
37
|
has_rdoc: false
|
37
38
|
homepage: http://www.linkedin.com/in/jerryluk
|