Sha256: 29214121309a2de9a5051369b708ba5ccbee54a95972e10ae482b60fe89c6dcd

Contents?: true

Size: 1.5 KB

Versions: 14

Compression:

Stored size: 1.5 KB

Contents

module IcalImporter
  class RemoteEvent
    attr_accessor :event, :utc
    alias :utc? :utc
    delegate :uid, :summary, :location, :recurrence_id, :description, :recurs?, :rrule_property, :exdate, :to => :event

    def initialize(event)
      @event = event
      begin
        @utc = @event.dtstart.try(:tzid) != :floating
      rescue
        @utc = true
      end
    end

    def start_date_time
      get_date_time_for :dtstart
    end

    def end_date_time
      get_date_time_for :dtend
    end

    def all_day_event?
      begin
        (Time.parse(end_date_time.to_s) - Time.parse(start_date_time.to_s)) >= 1.day
      rescue ArgumentError => e # no time info in '', Defaulting to false
        false
      end
    end

    def event_attributes
      {
        :uid => uid,
        :title => summary,
        :utc => utc?,
        :description => description,
        :location => location || '',
        :start_date_time => start_date_time,
        :end_date_time => end_date_time,
        :all_day_event => all_day_event?
      }
    end

    private

    def get_date_time_for(event_method)
      event_method = event_method.to_sym
      raise ArgumentError, "Should be dtend or dtstart" unless [:dtstart, :dtend].include? event_method
      event_time = event.send event_method
      if event_time.is_a? DateTime
        (event_time.tzid == :floating) ? event_time : event_time.utc
      else
        begin
          event_time.to_datetime
        rescue
          event_time
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
ical_importer-0.2.0 lib/ical_importer/remote_event.rb
ical_importer-0.1.3 lib/ical_importer/remote_event.rb
ical_importer-0.1.2 lib/ical_importer/remote_event.rb
ical_importer-0.1.1 lib/ical_importer/remote_event.rb
ical_importer-0.1.0 lib/ical_importer/remote_event.rb
ical_importer-0.0.19 lib/ical_importer/remote_event.rb
ical_importer-0.0.18 lib/ical_importer/remote_event.rb
ical_importer-0.0.17 lib/ical_importer/remote_event.rb
ical_importer-0.0.16 lib/ical_importer/remote_event.rb
ical_importer-0.0.15 lib/ical_importer/remote_event.rb
ical_importer-0.0.14 lib/ical_importer/remote_event.rb
ical_importer-0.0.13 lib/ical_importer/remote_event.rb
ical_importer-0.0.12 lib/ical_importer/remote_event.rb
ical_importer-0.0.11 lib/ical_importer/remote_event.rb