Sha256: 4cea6aac8fb8727da5732a8dbcfbe23452d32d68e62785d1e4b7b82113a76450
Contents?: true
Size: 1.31 KB
Versions: 3
Compression:
Stored size: 1.31 KB
Contents
require 'forwardable' module Almanack class Calendar ONE_HOUR = 60 * 60 ONE_DAY = 24 * ONE_HOUR ONE_MONTH = 30 * ONE_DAY ONE_YEAR = 365 * ONE_DAY extend Forwardable def_delegators :@config, :event_sources, :title, :days_lookahead def initialize(config) @config = config end def events now = Time.now future = now + days_lookahead * ONE_DAY events_between(now..future) end def events_between(date_range) event_sources.map do |event_source| event_source.events_between(date_range) end.flatten.sort_by(&:start_date) end def ical_feed now = Time.now future = now + ONE_YEAR # Three hours is the duration for events missing end dates, a # recommendation suggested by Meetup.com. three_hours = 3 * ONE_HOUR ical = RiCal.Calendar events_between(now..future).each do |event| ical_event = RiCal.Event ical_event.summary = event.title ical_event.dtstart = event.start_date.utc ical_event.dtend = (event.end_date || event.start_date + three_hours).utc ical_event.description = event.description if event.description ical_event.location = event.location if event.location ical.add_subcomponent(ical_event) end ical.to_s end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
almanack-1.0.3 | lib/almanack/calendar.rb |
almanack-1.0.2 | lib/almanack/calendar.rb |
almanack-1.0.1 | lib/almanack/calendar.rb |