Module: ICalPal

Included in:
Calendar, Event, Store
Defined in:
lib/icalPal.rb,
lib/rdt.rb,
lib/event.rb,
lib/store.rb,
lib/options.rb,
lib/calendar.rb

Overview

Encapsulate the Store (accounts), Calendar and CalendarItem tables of a Calendar database

Defined Under Namespace

Classes: Calendar, Event, Options, RDT, Store

Constant Summary collapse

ITIME =

Epoch + 31 years

978307200
DOW =

Days of the week abbreviations used in recurrence rules

SU, MO, TU, WE, TH, FR, SA

{ 'SU': 0, 'MO': 1, 'TU': 2, 'WE': 3, 'TH': 4, 'FR': 5, 'SA': 6 }

Instance Attribute Summary collapse

Accessors collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#selfObject (readonly)

Returns the value of attribute self.



12
13
14
# File 'lib/icalPal.rb', line 12

def self
  @self
end

Class Method Details

.call(klass) ⇒ Class

Dynamic instantiation of our classes based on the command being run

Parameters:

  • klass (String)

    One of accounts, stores, calendars, or events

Returns:

  • (Class)

    The subclass of ICalPal



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/icalPal.rb', line 19

def self.call(klass)
  case klass
  when 'accounts' then Store
  when 'stores' then Store
  when 'calendars' then Calendar
  when 'events' then Event
  when 'tasks' then Task
  else
    $log.fatal("Unknown class: #{klass}")
    exit
  end
end

.nth(n, dow, m) ⇒ RDT

Get the n‘th dow in month m

Parameters:

  • n (Integer)

    Integer between -4 and +4

  • dow (String)

    Day of the week abbreviation from ICalPal::DOW

  • m (RDT)

    The RDT with the year and month we’re searching

Returns:

  • (RDT)

    The resulting day



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/icalPal.rb', line 52

def self.nth(n, dow, m)
  # Get the number of days in the month
  a = [ ICalPal::RDT.new(m.year, m.month, 1) ] # First of this month
  a[1] = (a[0] >> 1) - 1      # First of next month, minus 1 day

  # Reverse it if going backwards
  a.reverse! if n.negative?
  step = a[1] <=> a[0]

  j = 0
  a[0].step(a[1], step) do |i|
    j += step if i.wday == DOW[dow.to_sym]
    return i if j == n
  end
end

Instance Method Details

#[](k) ⇒ Object



77
# File 'lib/icalPal.rb', line 77

def [](k) @self[k] end

#[]=(k, v) ⇒ Object



78
# File 'lib/icalPal.rb', line 78

def []=(k, v) @self[k] = v end

#initialize(obj) ⇒ Object

Parameters:

  • obj (ICalPal)

    A Store or Calendar



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/icalPal.rb', line 33

def initialize(obj)
  obj['type'] = EventKit::EKSourceType.find_index { |i| i[:name] == 'Subscribed' } if obj['subcal_url']
  type = EventKit::EKSourceType[obj['type']]

  obj['store'] = obj['account']

  obj['type'] = type[:name]
  obj['color'] ||= type[:color]
  obj['symbolic_color_name'] ||= type[:color]

  @self = obj
end

#keysObject



79
# File 'lib/icalPal.rb', line 79

def keys() @self.keys end

#valuesObject



80
# File 'lib/icalPal.rb', line 80

def values() @self.values end