http://github.com/icalendar/icalendar
더 나은 문서가 계속 제공될 예정이지만 그 동안 1.x에서 2.0으로 이동하는 데 필요한 변경 사항은 README를 업데이트하는 데 필요한 차이점으로 요약됩니다.
iCalendar는 RFC-5545에 정의된 iCalendar 형식의 iCalendar 파일을 처리하기 위한 Ruby 라이브러리입니다.
require 'icalendar'
# Create a calendar with an event (standard method)
cal = Icalendar :: Calendar . new
cal . event do | e |
e . dtstart = Icalendar :: Values :: Date . new ( '20050428' )
e . dtend = Icalendar :: Values :: Date . new ( '20050429' )
e . summary = "Meeting with the man."
e . description = "Have a long lunch meeting and decide nothing..."
e . ip_class = "PRIVATE"
end
cal . publish
event = Icalendar :: Event . new
event . dtstart = DateTime . civil ( 2006 , 6 , 23 , 8 , 30 )
event . summary = "A great event!"
cal . add_event ( event )
event2 = cal . event # This automatically adds the event to the calendar
event2 . dtstart = DateTime . civil ( 2006 , 6 , 24 , 8 , 30 )
event2 . summary = "Another great event!"
params = { "altrep" => "http://my.language.net" , "language" => "SPANISH" }
event = cal . event do | e |
e . dtstart = Icalendar :: Values :: Date . new ( '20050428' )
e . dtend = Icalendar :: Values :: Date . new ( '20050429' )
e . summary = Icalendar :: Values :: Text . new "This is a summary with params." , params
end
event . summary . ical_params #=> {'altrep' => 'http://my.language.net', 'language' => 'SPANISH'}
# or
event = cal . event do | e |
e . dtstart = Icalendar :: Values :: Date . new ( '20050428' )
e . dtend = Icalendar :: Values :: Date . new ( '20050429' )
e . summary = "This is a summary with params."
e . summary . ical_params = params
end
event . summary . ical_params #=> {'altrep' => 'http://my.language.net', 'language' => 'SPANISH'}
때때로 우리는 이벤트의 시작이나 끝이 Date
또는 DateTime
객체인지 상관하지 않습니다. 이를 위해 DateOrDateTime.new(value)
사용할 수 있습니다. 반환된 DateOrDateTime
에 대해 .call
호출하면 기본 Date
또는 DateTime
객체가 즉시 반환됩니다.
event = cal . event do | e |
e . dtstart = Icalendar :: Values :: DateOrDateTime . new ( '20140924' )
e . dtend = Icalendar :: Values :: DateOrDateTime . new ( '20140925' ) . call
e . summary = 'This is an all-day event, because DateOrDateTime will return Dates'
end
이벤트와 관련된 URL을 구문 분석하고 표시할 수 있는 클라이언트의 경우 URL을 할당할 수 있습니다.
event = cal . event do | e |
e . url = 'https://example.com'
end
cal_string = cal.to_ical
puts cal_string
cal . event do | e |
# ...other event properties
e . alarm do | a |
a . action = "EMAIL"
a . description = "This is an event reminder" # email body (required)
a . summary = "Alarm notification" # email subject (required)
a . attendee = %w( mailto:[email protected] mailto:[email protected] ) # one or more email recipients (required)
a . append_attendee "mailto:[email protected]"
a . trigger = "-PT15M" # 15 minutes before
a . append_attach Icalendar :: Values :: Uri . new ( "ftp://host.com/novo-procs/felizano.exe" , "fmttype" => "application/binary" ) # email attachments (optional)
end
e . alarm do | a |
a . action = "DISPLAY" # This line isn't necessary, it's the default
a . summary = "Alarm notification"
a . trigger = "-P1DT0H0M0S" # 1 day before
end
e . alarm do | a |
a . action = "AUDIO"
a . trigger = "-PT15M"
a . append_attach "Basso"
end
end
# BEGIN:VALARM
# ACTION:EMAIL
# ATTACH;FMTTYPE=application/binary:ftp://host.com/novo-procs/felizano.exe
# TRIGGER:-PT15M
# SUMMARY:Alarm notification
# DESCRIPTION:This is an event reminder
# ATTENDEE:mailto:[email protected]
# ATTENDEE:mailto:[email protected]
# END:VALARM
#
# BEGIN:VALARM
# ACTION:DISPLAY
# TRIGGER:-P1DT0H0M0S
# SUMMARY:Alarm notification
# END:VALARM
#
# BEGIN:VALARM
# ACTION:AUDIO
# ATTACH;VALUE=URI:Basso
# TRIGGER:-PT15M
# END:VALARM
존재하지 않는 경우 event.alarm
메소드를 호출하면 경보가 생성됩니다. 이벤트에 알람이 있는지 확인하려면 has_alarm?
방법.
event . has_alarm?
# => false
event . alarm
# => #<Icalendar::Alarm ... >
event . has_alarm?
#=> true
cal = Icalendar :: Calendar . new
cal . timezone do | t |
t . tzid = "America/Chicago"
t . daylight do | d |
d . tzoffsetfrom = "-0600"
d . tzoffsetto = "-0500"
d . tzname = "CDT"
d . dtstart = "19700308T020000"
d . rrule = "FREQ=YEARLY;BYMONTH=3;BYDAY=2SU"
end
t . standard do | s |
s . tzoffsetfrom = "-0500"
s . tzoffsetto = "-0600"
s . tzname = "CST"
s . dtstart = "19701101T020000"
s . rrule = "FREQ=YEARLY;BYMONTH=11;BYDAY=1SU"
end
end
# BEGIN:VTIMEZONE
# TZID:America/Chicago
# BEGIN:DAYLIGHT
# TZOFFSETFROM:-0600
# TZOFFSETTO:-0500
# TZNAME:CDT
# DTSTART:19700308T020000
# RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU
# END:DAYLIGHT
# BEGIN:STANDARD
# TZOFFSETFROM:-0500
# TZOFFSETTO:-0600
# TZNAME:CST
# DTSTART:19701101T020000
# RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU
# END:STANDARD
# END:VTIMEZONE
iCalendar는 tzinfo
에서 가져온 시간대 정보에서 VTIMEZONE 블록을 생성하기 위한 몇 가지 기본 지원을 제공합니다. 이점을 활용하려면 tzinfo
지원을 수동으로 요구해야 합니다.
iCalendar는 테스트를 거쳤으며 tzinfo
버전 0.3, 1.x 및 2.x에서 작동합니다. tzinfo-data
gem은 tzinfo
버전과 운영 체제에 따라 필요할 수도 있습니다.
require 'icalendar/tzinfo'
cal = Icalendar :: Calendar . new
event_start = DateTime . new 2008 , 12 , 29 , 8 , 0 , 0
event_end = DateTime . new 2008 , 12 , 29 , 11 , 0 , 0
tzid = "America/Chicago"
tz = TZInfo :: Timezone . get tzid
timezone = tz . ical_timezone event_start
cal . add_timezone timezone
cal . event do | e |
e . dtstart = Icalendar :: Values :: DateTime . new event_start , 'tzid' => tzid
e . dtend = Icalendar :: Values :: DateTime . new event_end , 'tzid' => tzid
e . summary = "Meeting with the man."
e . description = "Have a long lunch meeting and decide nothing..."
e . organizer = "mailto:[email protected]"
e . organizer = Icalendar :: Values :: CalAddress . new ( "mailto:[email protected]" , cn : 'John Smith' )
end
# Open a file or pass a string to the parser
cal_file = File . open ( "single_event.ics" )
# Parser returns an array of calendars because a single file
# can have multiple calendars.
cals = Icalendar :: Calendar . parse ( cal_file )
cal = cals . first
# Now you can access the cal object in just the same way I created it
event = cal . events . first
puts "start date-time: #{ event . dtstart } "
puts "start date-time timezone: #{ event . dtstart . ical_params [ 'tzid' ] } "
puts "summary: #{ event . summary } "
Parser
인스턴스를 직접 생성할 수도 있으며 이를 사용하여 엄격한 구문 분석을 활성화할 수 있습니다.
# Sometimes you want to strongly verify only rfc-approved properties are
# used
strict_parser = Icalendar :: Parser . new ( cal_file , true )
cal = strict_parser . parse
# Open a file or pass a string to the parser
event_file = File . open ( "event.ics" )
# Parser returns an array of events because a single file
# can have multiple events.
events = Icalendar :: Event . parse ( event_file )
event = events . first
puts "start date-time: #{ event . dtstart } "
puts "start date-time timezone: #{ event . dtstart . ical_params [ 'tzid' ] } "
puts "summary: #{ event . summary } "
웹 앱 및 기타 대화형 애플리케이션에서는 변경 사항을 적용하거나 세부 정보를 얻기 위해 달력의 항목을 조회해야 하는 경우가 많습니다. 이제 모든 구성 요소와 자동으로 연결된 고유 ID로 모든 것을 찾을 수 있습니다.
cal = Calendar . new
10 . times { cal . event } # Create 10 events with only default data.
some_event = cal . events [ 5 ] # Grab it from the array of events
# Use the uid as the key in your app
key = some_event . uid
# so later you can find it.
same_event = cal . find_event ( key )
수행하고 싶은 대부분의 작업에 대한 예를 단위 테스트에서 확인하세요. 예제 코드를 보내주시거나 누락된 부분을 알려주시기 바랍니다.
이 라이브러리의 최신 릴리스 버전은 다음에서 찾을 수 있습니다.
루비젬에 관한 모든 것:
$ gem install icalendar
테스트를 실행하려면 다음 안내를 따르세요.
$ bundle install
$ rake spec
이 라이브러리는 Ruby 자체와 동일한 라이센스로 출시됩니다.
리베이스된 주제 브랜치에서 풀 요청을 제출하고 모든 버그 및 기능에 대한 테스트를 포함하세요.
이 프로젝트의 기여자이자 유지관리자로서 우리는 문제 보고, 기능 요청 게시, 문서 업데이트, 풀 요청 또는 패치 제출 및 기타 활동을 통해 기여하는 모든 사람을 존중할 것을 약속합니다.
우리는 경험 수준, 성별, 성 정체성 및 표현, 성적 취향, 장애, 외모, 신체 크기, 인종, 민족, 연령 또는 종교에 관계없이 모든 사람이 이 프로젝트에 참여하여 괴롭힘 없는 경험을 할 수 있도록 최선을 다하고 있습니다.
참가자가 용납할 수 없는 행동의 예로는 성적인 언어나 이미지의 사용, 경멸적인 발언이나 인신공격, 트롤링, 공개적 또는 사적 괴롭힘, 모욕, 기타 비전문적인 행위 등이 있습니다.
프로젝트 관리자는 본 행동 강령에 부합하지 않는 댓글, 커밋, 코드, Wiki 편집, 문제 및 기타 기여를 제거, 편집 또는 거부할 권리와 책임이 있습니다. 행동 강령을 따르지 않는 프로젝트 유지관리자는 프로젝트 팀에서 제외될 수 있습니다.
이 행동 강령은 개인이 프로젝트나 해당 커뮤니티를 대표할 때 프로젝트 공간과 공공 장소 모두에 적용됩니다.
욕설, 괴롭힘 또는 기타 용납할 수 없는 행위의 사례는 문제를 공개하거나 프로젝트 관리자 중 한 명 이상에게 연락하여 보고할 수 있습니다.
본 행동 강령은 http://contributor-covenant.org/version/1/1/0/에서 제공되는 기여자 규약 버전 1.1.0에서 수정되었습니다.