class ICalendar

iCal

Public Class Methods

new(file = nil) click to toggle source
# File lib/hanreki/i_calendar.rb, line 7
def initialize(file = nil)
  @calendar = Icalendar::Calendar.new
  if file
    @calendar = Icalendar.parse(file).first
  else
    make_blank
  end
end

Public Instance Methods

set_event(event, type) click to toggle source
# File lib/hanreki/i_calendar.rb, line 21
def set_event(event, type)
  fail ValidationError.new(event), 'invalid date' unless event.start && event.end
  fail ValidationError.new(event), 'invalid type' unless [:public, :private].include?(type)
  @calendar.event do |e|
    e.dtstart = event.start
    e.dtend = event.end
    e.url = event.url
    case type
    when :public then e.summary = event.public_summary
    when :private then e.summary = event.private_summary
    end
  end
end
to_s() click to toggle source
# File lib/hanreki/i_calendar.rb, line 16
def to_s
  @calendar.publish
  @calendar.to_ical
end

Private Instance Methods

make_blank() click to toggle source

Generate new calendar

# File lib/hanreki/i_calendar.rb, line 38
def make_blank
  @calendar.append_custom_property('X-WR-CALNAME', 'CAMPHOR- Events')
  set_timezone
end
set_timezone() click to toggle source
# File lib/hanreki/i_calendar.rb, line 43
def set_timezone
  # TODO: Rewrite with tzinfo
  @calendar.timezone do |t|
    t.tzid = 'Asia/Tokyo'
    t.standard do |s|
      s.tzoffsetfrom = '+0900'
      s.tzoffsetto   = '+0900'
      s.tzname       = 'JST'
      s.dtstart      = '19700101T000000'
    end
  end
end