Class: ICalPal::Reminder

Inherits:
Object
  • Object
show all
Includes:
ICalPal
Defined in:
lib/reminder.rb

Overview

Class representing items from the Reminders database

Constant Summary

Constants included from ICalPal

DOW, ITIME, NAME, VERSION

Instance Attribute Summary

Attributes included from ICalPal

#self

Instance Method Summary collapse

Methods included from ICalPal

#[]=, call, #keys, load_data, nth, #to_csv, #to_xml, #values, #xmlify

Constructor Details

#initialize(obj) ⇒ Reminder

Returns a new instance of Reminder.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/reminder.rb', line 24

def initialize(obj)
  @self = {}
  obj.keys.each { |k| @self[k] = obj[k] }

  # Priority
  @self['prio'] = 0 if @self['priority'] == 1 # high
  @self['prio'] = 1 if @self['priority'] == 5 # medium
  @self['prio'] = 2 if @self['priority'] == 9 # low
  @self['prio'] = 3 if @self['priority'] == 0 # none

  @self['long_priority'] = LONG_PRIORITY[@self['prio']]

  # For sorting
  @self['sdate'] = (@self['title'])? @self['title'] : ""

  # Due date
  @self['due'] = RDT.new(*Time.at(@self['due_date'] + ITIME).to_a.reverse[4..]) if @self['due_date']
  @self['due_date'] = 0 unless @self['due_date']

  # Notes
  @self['notes'] = "" unless @self['notes']

  # Color
  @self['color'] = nil unless $opts[:palette]

  if @self['color'] then
    # Run command
    stdin, stdout, stderr, e = Open3.popen3(PL_CONVERT)

    # Send color bplist
    stdin.write(@self['color'])
    stdin.close

    # Read output
    plist = Nokogiri::PList(stdout.read)['$objects']

    @self['color'] = plist[3]
    @self['symbolic_color_name'] = (plist[2] == 'custom')? plist[4] : plist[2]
  else
    @self['color'] = DEFAULT_COLOR
    @self['symbolic_color_name'] = DEFAULT_SYMBOLIC_COLOR
  end
end

Instance Method Details

#[](k) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/reminder.rb', line 9

def [](k)
  case k
  when 'notes' then         # Skip empty notes
    @self['notes'].length > 0? @self['notes'] : nil

  when 'priority' then      # Integer -> String
    EventKit::EKReminderProperty[@self['priority']] if @self['priority'] > 0

  when 'sdate' then         # For sorting
    @self['title']

  else @self[k]
  end
end