2015-09-07 30 views
2

我添加事件的iCalendar:它可能與只有一個事件與ruby-iCalendar出口VCalendar?

require 'icalendar' 
calendar = Icalendar::Calendar.new 
...some properties to calendar 
event = Icalendar::Event.new 
...some properties to event 1 
calendar.add_event(event) 
event = Icalendar::Event.new 
...some properties to event 2 
calendar.add_event(event) 

當我打電話到輸出全日曆出版(簡體)

calendar.to_ical 

BEGIN:VCALENDAR 
BEGIN:VEVENT 
...event 1 
END:VEVENT 
BEGIN:VEVENT 
...event 2 
END:VEVENT 
END:VCALENDAR 

如果我把事件1只

event.to_ical 

BEGIN:VEVENT 
...event 1 
END:VEVENT 
的輸出

我想輸出只有這個事件的VCalendar(如過濾器)

BEGIN:VCALENDAR 
BEGIN:VEVENT 
...event 1 
END:VEVENT 
END:VCALENDAR 

有沒有日曆對象的方法?

回答

0
require 'icalendar' 
calendar = Icalendar::Calendar.new 
...some properties to calendar 
event = Icalendar::Event.new 
...some properties to event 1 
calendar.add_event(event) 
calendar_as_string = "BEGIN:VCALENDAR\n#{event.to_ical}\nEND:VCALENDAR" 

一點點的黑客,但它應該排序你...什麼calendar.to_ical打印?根據tests,它看起來會做你所需要的。

+0

這不是我在找什麼,因爲有很多屬性添加到日曆(和時區)。 – Buschhardt

+0

我提出了兩種可能的解決方案 - 一種是黑客攻擊,另一種是來自寶石的測試。哪一個不是你要找的? – hd1

0

我到了這一刻的解決辦法是,擴大類:

class Icalendar::Event 
    attr_accessor :vcard 
end 

ca = Icalendar::Calendar.new 
ca.add_timezone blah 
...some properties to calendar 
cax = Icalendar::Calendar.new 
cax.add_timezone blah 
...some properties to calendar 
event = Icalendar::Event.new 
... add some properties to event 
cax.add_event(event) 
event.vcard= cax.to_ical 
ca.add_event(event) 

puts ca.find_event(uid).vcard 

但我覺得應該有一個更優雅的方式來做到這一點。謝謝

相關問題