Class: Waddup::Source::AppleCalendar

Inherits:
Waddup::Source show all
Extended by:
Extension::AppleScript, Extension::FileSystem
Includes:
Extension::AppleScript
Defined in:
lib/waddup/sources/apple_calendar.rb

Constant Summary collapse

ALIAS =
'ical'
ICON =
"\xF0\x9F\x93\x85 "
EVENT_SCRIPT =
folder_of(__FILE__) + 'apple_calender/events.applescript'

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Extension::AppleScript

applescript, applescript?

Methods included from Extension::System

#os, #osx?, #run

Methods included from Extension::FileSystem

folder_of

Methods inherited from Waddup::Source

usable, #usable?

Methods included from Registry

#inherited, #registry

Class Method Details

.usable?Boolean

Requires AppleScript to be available

Returns:

  • (Boolean)


36
37
38
# File 'lib/waddup/sources/apple_calendar.rb', line 36

def self.usable?
  applescript?
end

Instance Method Details

#events(from, to) ⇒ Object

Aggregates calendar events

Arguments:

:from (datetime)
:to   (datetime)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/waddup/sources/apple_calendar.rb', line 20

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