Sha256: c65abfbbbb156f0c6addbafa12520650c068b36954b548f5aea858e7055af105

Contents?: true

Size: 979 Bytes

Versions: 4

Compression:

Stored size: 979 Bytes

Contents

module Waddup

  class Source::AppleCalendar < Waddup::Source
    include Waddup::Extension::AppleScript
    extend Waddup::Extension::AppleScript
    extend Waddup::Extension::FileSystem

    ALIAS = 'ical'
    ICON  = "\xF0\x9F\x93\x85 "

    EVENT_SCRIPT = folder_of(__FILE__) + 'apple_calender/events.applescript'

    # Aggregates calendar events
    #
    # Arguments:
    #
    #   :from (datetime)
    #   :to   (datetime)
    #
    def events(from, to)
      results = applescript EVENT_SCRIPT,
        as_ruby: true,
        args:    [from.strftime('%d/%m/%Y %H:%M'), to.strftime('%d/%m/%Y %H:%M')]

      results.map do |result|
        Waddup::Event.new do |e|
          e.label   = result[:summary]
          e.at      = Time.parse(result[:start_date])
          e.until   = Time.parse(result[:end_date])
          e.source  = self
        end
      end
    end

    # Requires AppleScript to be available
    def self.usable?
      applescript?
    end

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
waddup-0.2.2 lib/waddup/sources/apple_calendar.rb
waddup-0.2.1 lib/waddup/sources/apple_calendar.rb
waddup-0.2.0 lib/waddup/sources/apple_calendar.rb
waddup-0.1.0 lib/waddup/sources/apple_calendar.rb