jerryluk-jruby-rfc2445 0.0.2 → 0.0.3
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/ical_parse_util.rb +51 -0
- metadata +2 -2
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'java'
|
2
|
+
require File.dirname(__FILE__) + '/rfc2445.jar'
|
3
|
+
|
4
|
+
class ICalParseUtil
|
5
|
+
include_class('com.google.ical.values.IcalParseUtil'){|package,name| "J#{name}" }
|
6
|
+
|
7
|
+
# Class Methods
|
8
|
+
class << self
|
9
|
+
def parse_date_value(s, tzid = 'UTC')
|
10
|
+
timezone = java.util.TimeZone.getTimeZone(tzid)
|
11
|
+
s ? JIcalParseUtil.parseDateValue(s, timezone) : nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def parse_jtime(s, tzid = 'UTC')
|
15
|
+
s ? JTime.from_date_time_value(parse_date_value(s, tzid)) : nil
|
16
|
+
end
|
17
|
+
|
18
|
+
# Parse a recurrence block and returns DTSTART, DTEND, RRULE, EXRULE, RDATE, and EXDATE
|
19
|
+
def parse_recurrence(s)
|
20
|
+
result = {}
|
21
|
+
|
22
|
+
# Strip out all the begin..end blocks
|
23
|
+
s = s.gsub(/BEGIN.*END[^\s]+/m, '')
|
24
|
+
|
25
|
+
s =~ /(DTSTART[^\s]+)/
|
26
|
+
result[:dtstart] = $1 if $1
|
27
|
+
|
28
|
+
s =~ /(DTEND[^\s]+)/
|
29
|
+
result[:dtend] = $1 if $1
|
30
|
+
|
31
|
+
s =~ /(RRULE[^\s]+)/
|
32
|
+
result[:rrule] = $1 if $1
|
33
|
+
|
34
|
+
s =~ /(EXRULE[^\s]+)/
|
35
|
+
result[:exrule] = $1 if $1
|
36
|
+
|
37
|
+
s =~ /(RDATE[^\s]+)/
|
38
|
+
result[:rdate] = $1 if $1
|
39
|
+
|
40
|
+
s =~ /(EXDATE[^\s]+)/
|
41
|
+
result[:exdate] = $1 if $1
|
42
|
+
|
43
|
+
result
|
44
|
+
end
|
45
|
+
|
46
|
+
def parse_datetime(s)
|
47
|
+
s =~ /(;TZID=([^\s]+))?:([^\s]+)/
|
48
|
+
parse_jtime($3, $2)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jerry Luk
|
@@ -24,7 +24,7 @@ extra_rdoc_files: []
|
|
24
24
|
files:
|
25
25
|
- README
|
26
26
|
- MIT-LICENSE
|
27
|
-
- lib/ical_parse_util.
|
27
|
+
- lib/ical_parse_util.rb
|
28
28
|
- lib/jtime.rb
|
29
29
|
- lib/rdate_list.rb
|
30
30
|
- lib/recurrence_time.rb
|