Class: ICalPal::Reminder
Overview
Class representing items from the Reminders
database
Constant Summary collapse
- DEFAULT_COLOR =
'#1BADF8'.freeze
- DEFAULT_SYMBOLIC_COLOR =
'blue'.freeze
- LONG_PRIORITY =
[ 'High priority', 'Medium priority', 'Low priority', 'No priority', ].freeze
- PL_CONVERT =
'/usr/bin/plutil -convert xml1 -o - -'.freeze
- DB_PATH =
"#{Dir.home}/Library/Group Containers/group.com.apple.reminders/Container_v1/Stores".freeze
- QUERY =
<<~SQL.freeze SELECT DISTINCT zremcdReminder.zAllday as all_day, zremcdReminder.zDuedate as due_date, zremcdReminder.zFlagged as flagged, zremcdReminder.zNotes as notes, zremcdReminder.zPriority as priority, zremcdReminder.zTitle as title, zremcdBaseList.zBadgeEmblem as badge, zremcdBaseList.zColor as color, zremcdBaseList.zName as list_name, zremcdBaseList.zParentList as parent, zremcdBaseList.zSharingStatus as shared FROM zremcdReminder JOIN zremcdBaseList ON zremcdReminder.zList = zremcdBaseList.z_pk WHERE zremcdReminder.zCompleted = 0 AND zremcdReminder.zMarkedForDeletion = 0 SQL
Constants included from ICalPal
Instance Attribute Summary
Attributes included from ICalPal
Instance Method Summary collapse
- #[](k) ⇒ Object
-
#initialize(obj) ⇒ Reminder
constructor
A new instance of Reminder.
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 67 68 |
# File 'lib/reminder.rb', line 24 def initialize(obj) @self = {} obj.each_key { |k| @self[k] = obj[k] } # Priority # rubocop: disable Style/NumericPredicate @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 # rubocop: enable Style/NumericPredicate @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'] # 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' # Skip empty notes (@self['notes'].empty?)? @self['notes'] : nil when 'priority' # Integer -> String EventKit::EKReminderProperty[@self['priority']] if @self['priority'].positive? when 'sdate' # For sorting @self['title'] else @self[k] end end |