Class: ICalParseUtil
- Inherits:
-
Object
- Object
- ICalParseUtil
- Defined in:
- lib/ical_parse_util.rb
Class Method Summary collapse
- .parse_date_value(s, tzid = 'UTC') ⇒ Object
- .parse_datetime(s, tzid = nil) ⇒ Object
- .parse_jtime(s, tzid = 'UTC') ⇒ Object
-
.parse_recurrence(s) ⇒ Object
Parse a recurrence block and returns DTSTART, DTEND, RRULE, EXRULE, RDATE, and EXDATE.
-
.parse_recurrence_id(s, tzid = 'UTC') ⇒ Object
Parse a RECURRENCE-ID into a JTime.
Class Method Details
.parse_date_value(s, tzid = 'UTC') ⇒ Object
11 12 13 14 |
# File 'lib/ical_parse_util.rb', line 11 def parse_date_value(s, tzid = 'UTC') timezone = java.util.TimeZone.get_time_zone(tzid || 'UTC') s ? JIcalParseUtil.parse_date_value(s, timezone) : nil end |
.parse_datetime(s, tzid = nil) ⇒ Object
70 71 72 73 |
# File 'lib/ical_parse_util.rb', line 70 def parse_datetime(s, tzid = nil) s =~ /(;TZID=([^\s]+))?:([^\s]+)/ parse_jtime($3, $2 || tzid) end |
.parse_jtime(s, tzid = 'UTC') ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ical_parse_util.rb', line 16 def parse_jtime(s, tzid = 'UTC') return nil unless s value = parse_date_value(s, tzid) case value when DateTimeValue JTime.from_date_time_value(value) when DateValue timezone = org.joda.time.DateTimeZone.forID(tzid) JTime.from_date_value(value, timezone) end end |
.parse_recurrence(s) ⇒ Object
Parse a recurrence block and returns DTSTART, DTEND, RRULE, EXRULE, RDATE, and EXDATE
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ical_parse_util.rb', line 29 def parse_recurrence(s) result = {} # Strip out all the begin..end blocks s = s.gsub(/BEGIN.*END[^\s]+/m, '') s =~ /(DTSTART[^\s]+)/ result[:dtstart] = $1 if $1 s =~ /(DTEND[^\s]+)/ result[:dtend] = $1 if $1 s =~ /(RRULE[^\s]+)/ result[:rrule] = $1 if $1 s =~ /(EXRULE[^\s]+)/ result[:exrule] = $1 if $1 s =~ /(RDATE[^\s]+)/ result[:rdate] = $1 if $1 s =~ /(EXDATE[^\s]+)/ result[:exdate] = $1 if $1 result end |
.parse_recurrence_id(s, tzid = 'UTC') ⇒ Object
Parse a RECURRENCE-ID into a JTime. Various formats of this property are permitted, except for the “range” parameter
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/ical_parse_util.rb', line 59 def parse_recurrence_id(s, tzid = 'UTC') raise ArgumentError, 'range parameter not supported' if s =~ /RANGE=/ s =~ /TZID=([^:;]+)/ tzid = $1 || tzid # Clean up ISO 8601 format and extra parameters s = s.gsub(/;[^:]+:|[\-:]/, '') parse_jtime(s, tzid) end |