ruby - 是否可以使用 ruby​​-iCalendar 导出只有一个事件的 VCalendar?

标签 ruby icalendar

我将事件添加到 iCalendar:

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

日历对象有办法吗?

最佳答案

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"

有点hack,但它应该对你进行排序...... calendar.to_ical 打印什么?根据tests ,看起来它会做你需要的。

关于ruby - 是否可以使用 ruby​​-iCalendar 导出只有一个事件的 VCalendar?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32434657/

相关文章:

ios - iCal 事件 - 通过 iOS 应用程序以编程方式添加

javascript - HTML:iCal 链接?

calendar - ics 闹钟未出现在 Google 日历或 Outlook 中

ruby-on-rails - 如何仅从电子邮件内容中获取文本? Ruby on Rails - 用于 Ruby Gem 的 GMail

ruby - nanoc:如何将选项传递给 pandoc-ruby?

javascript - 使用 fullcalendar 导入 iCal (ics)?

android - iCal - 初学者教程和文档?

ruby-on-rails - rails 日志问题

ruby-on-rails - Rails 3.1 中具有相同形式的多个模型?

ruby-on-rails - 从 Bash -> Docker 按名称 -> Ruby -> 清除缓存