Method: ICalPal::Reminder#initialize

Defined in:
lib/reminder.rb

#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