Class: Calagator::VCalendar

Inherits:
Struct
  • Object
show all
Defined in:
lib/calagator/vcalendar.rb

Constant Summary collapse

VENUE_CONTENT_RE =
/^BEGIN:VVENUE$.*?^END:VVENUE$/m.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#ri_cal_calendarObject

Returns the value of attribute ri_cal_calendar

Returns:

  • (Object)

    the current value of ri_cal_calendar



6
7
8
# File 'lib/calagator/vcalendar.rb', line 6

def ri_cal_calendar
  @ri_cal_calendar
end

Class Method Details

.parse(raw_ical) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/calagator/vcalendar.rb', line 7

def self.parse(raw_ical)
  raw_ical = raw_ical.gsub(/\r\n/, "\n") # normalize line endings
  raw_ical = raw_ical.gsub(/;TZID=GMT:(.*)/, ':\1Z') # normalize timezones

  RiCal.parse_string(raw_ical).map do |ri_cal_calendar|
    VCalendar.new(ri_cal_calendar)
  end
rescue Exception => e
  if /Invalid icalendar file/.match?(e.message)
    return false
  end # Invalid data, give up.

  raise # Unknown error, reraise
end

Instance Method Details

#veventsObject



22
23
24
25
26
# File 'lib/calagator/vcalendar.rb', line 22

def vevents
  ri_cal_calendar.events.map do |ri_cal_event|
    VEvent.new(ri_cal_event, vvenues)
  end
end

#vvenuesObject



30
31
32
33
34
# File 'lib/calagator/vcalendar.rb', line 30

def vvenues
  @vvenues ||= ri_cal_calendar.to_s.scan(VENUE_CONTENT_RE).map do |raw_ical_venue|
    VVenue.new(raw_ical_venue)
  end
end