Method: ICalPal::Event#initialize
- Defined in:
- lib/event.rb
#initialize(obj) ⇒ Event #initialize(obj<DateTime>) ⇒ Event
Returns a new instance of Event.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/event.rb', line 72 def initialize(obj) # Placeholder for days with no events return @self = { $opts[:sep] => obj, 'sdate' => obj, 'placeholder' => true, 'title' => 'Nothing.', } if DateTime === obj @self = {} obj.each_key { |k| @self[k] = obj[k] } # Convert JSON arrays to Arrays @self['attendees'] = JSON.parse(obj['attendees']) # rubocop: disable Lint/UselessAssignment @self['xdate'] = JSON.parse(obj['xdate']).map do |k| k = RDT.new(*Time.at(k + ITIME).to_a.reverse[4..]) if k end # rubocop: enable Lint/UselessAssignment # Convert iCal dates to normal dates obj.keys.select { |i| i.end_with? '_date' }.each do |k| t = Time.at(obj[k] + ITIME) if obj[k] @self["#{k[0]}date"] = RDT.new(*t.to_a.reverse[4..], t.zone) if t end if @self['start_tz'] == '_float' tzoffset = Time.zone_offset($now.zone) @self['sdate'] = RDT.new(*(@self['sdate'].to_time - tzoffset).to_a.reverse[4..], $now.zone) @self['edate'] = RDT.new(*(@self['edate'].to_time - tzoffset).to_a.reverse[4..], $now.zone) end # Type of calendar event is from obj['type'] = EventKit::EKSourceType.find_index { |i| i[:name] == 'Subscribed' } if obj['subcal_url'] type = EventKit::EKSourceType[obj['type']] @self['symbolic_color_name'] ||= @self['color'] @self['type'] = type[:name] end |