我有一个 rake 任务设置,它使用 iCalendar gem从iCal 文件中导入事件。除标准 .ics 字段外,iCal 还包含几个自定义字段。是否也可以导入这些值?
iCal 文件中这样的行我可以毫无问题地处理:
DESCRIPTION:The lions and tigers are on exhibit.
像这样的行会出现问题:
X-TRUMBA-CUSTOMFIELD;NAME="Event Location";ID=10831;TYPE=SingleLine:Lower Level\,
across from the Stars and Stripes Cafe
我将如何引用自定义“事件位置”字段?
这是我到目前为止的代码:
desc "Import events from Smithsonian"
task :smithsonian => :environment do
url = "http://www.trumba.com/calendars/smithsonian-events.ics"
cals = Icalendar.parse(open(url))
cal = cals.first
cal.events.each do |event|
e = TempEvent.find_or_create_by_name(
:name => event.summary.to_s,
:description => event.description.to_s,
:starts_at => event.dtstart.to_s,
:ends_at => event.dtend.to_s,
:tag_list => event.categories,
:url => event.url,
:facebook_url => "https://www.facebook.com/Smithsonian",
:twitter_url => "https://twitter.com/smithsonian",
:venue_name => "Smithsonian",
:external_id => event.uid.to_s,
:source => "Smithsonian iCal import",
:published => true)
end
end