Class: Outlook2GCal::OutlookEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/outlook2gcal/outlook_calendar.rb

Constant Summary collapse

GCAL_MAX_REMINDER =

Note: The value of the minutes can be any arbitrary number of minutes between 5 minutes to 4 weeks.

40320
GCAL_MIN_REMINDER =

4 Weeks in minutes

5
APPOINTMENTTYPE =
{'0' =>:appointment,
'1' => :anniversary, 
'2' => :all_day_event,
'3' => :meeting,
'4' => :reminder}

Instance Method Summary collapse

Constructor Details

#initialize(outlook_event) ⇒ OutlookEvent

Returns a new instance of OutlookEvent.



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
112
113
114
115
116
117
118
# File 'lib/outlook2gcal/outlook_calendar.rb', line 80

def initialize(outlook_event)
  fill_alarm(outlook_event)   #TODO
  
  # Notes Id
  @uid = outlook_event.GlobalAppointmentID
  
  # Subject
  if outlook_event.Subject
     @subject = outlook_event.Subject
  else
     @subject = ''
     $logger.warn 'no subject. uid: '+@uid
  end 
 
  # Room/Location
  @where = outlook_event.Location || ''
  
  # start date + time
  @start_time = outlook_event.Start.to_s
  
  # end date + time
  @end_time =  outlook_event.End.to_s
  
  # event type  # TODO -> remove
  @appointmenttype = APPOINTMENTTYPE['3'] # Meeting
  
  #p outlook_event.LastModificationTime.to_s
  @last_modified = DateTime.parse(outlook_event.LastModificationTime.to_s)
  @content =  outlook_event.Body

  # -- neue 
  @all_day_event = outlook_event.AllDayEvent

 # fill_repeats(outlook_event)
 
  @chair = outlook_event.Organizer
  @required_names = outlook_event.RequiredAttendees
  @optional_names = outlook_event.OptionalAttendees
end

Instance Method Details

#_all_namesObject



179
180
181
182
183
184
185
186
# File 'lib/outlook2gcal/outlook_calendar.rb', line 179

def _all_names
  names = []
  names += @chair || [] 
  names += @required_names || []
  names += @optional_names || []
  
  names.uniq
end

#_fill_chair(outlook_event) ⇒ Object



192
193
194
195
196
# File 'lib/outlook2gcal/outlook_calendar.rb', line 192

def _fill_chair(outlook_event)
  chair = []
  chair << outlook_event.Organizer 
  chair
end

#_fill_names(outlook_event) ⇒ Object



187
188
189
190
191
# File 'lib/outlook2gcal/outlook_calendar.rb', line 187

def _fill_names(outlook_event)
  @chair = outlook_event.Organizer
  @required_names = outlook_event.RequiredAttendees
  @optional_names = outlook_event.OptionalAttendees
end

#_fill_notes_names(outlook_event, notes_attr_name, notes_attr_email = nil) ⇒ Object



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/outlook2gcal/outlook_calendar.rb', line 208

def _fill_notes_names(outlook_event, notes_attr_name, notes_attr_email = nil)
  names = []
  notes_names = []
  notes_names1 = outlook_event.GetFirstItem(notes_attr_name)
  if notes_attr_email 
    notes_names2 = outlook_event.GetFirstItem(notes_attr_email) 
    notes_names2 = nil unless (notes_names2 and notes_names2.Values.size == notes_names1.Values.size)
  end
  if notes_names1
    notes_names1.Values.each_with_index do |name, idx|
        email = find_email(notes_names2.Values, idx) if notes_names2
        #name =~ /^CN=(.*)\/O=(.*)\/C=(.*)/
        #email ? short_name = name.split('/')[0] : short_name  # use name+domain if email missing
        short_name = name.split('/')[0]
        # check if name is an email adress
        if !email and short_name =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
           email = short_name
           short_name = ''
        end
        names << {:name => (short_name || ''), :email => (email || '')}
    end
  end
  names
end

#_find_email(names, idx) ⇒ Object



197
198
199
200
201
202
203
204
205
206
# File 'lib/outlook2gcal/outlook_calendar.rb', line 197

def _find_email(names, idx)
  email = names[idx]     
  if email 
    email = nil if email == '.'
    email = nil if email == ''
    # email =~ /^CN=(.*)\/O=(.*)\/C=(.*)/
    # email = $1 if $1
  end
  return email
end

#_names_to_str(names) ⇒ Object



169
170
171
172
173
174
175
176
177
178
# File 'lib/outlook2gcal/outlook_calendar.rb', line 169

def _names_to_str(names)
  (names.inject([]) do |x,y| 
    if y[:email] and y[:email] != ''
       x << y[:email] if y[:email]
    elsif y[:name]
       x << y[:name] if y[:name]
    end
    x 
  end).join(', ')
end

#_names_to_str_name_email(names) ⇒ Object

obsolete methods -> TODO remove!!



158
159
160
161
162
163
164
165
166
167
# File 'lib/outlook2gcal/outlook_calendar.rb', line 158

def _names_to_str_name_email(names)
  (names.inject([]) do |x,y| 
    email, name = '', ''
    email = "<#{y[:email]}>" if (y[:email] and y[:email] != '')
    name = "\"#{y[:name]}\" " if (y[:name] and y[:name] != '')

    x << name + email
    x 
  end).join(', ')
end

#all_day?Boolean

Returns:

  • (Boolean)


119
120
121
# File 'lib/outlook2gcal/outlook_calendar.rb', line 119

def all_day?
  @all_day_event
end

#fill_alarm(outlook_event) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
# File 'lib/outlook2gcal/outlook_calendar.rb', line 133

def fill_alarm(outlook_event)
  # Alarm
  @alarm = false
  @alarm_offset = 0
  if outlook_event.ReminderSet
  then
    @alarm = true
    @alarm_offset = outlook_event.ReminderMinutesBeforeStart
  end

end

#fill_repeats(outlook_event) ⇒ Object



144
145
146
# File 'lib/outlook2gcal/outlook_calendar.rb', line 144

def fill_repeats(outlook_event)
  @repeats = []
end

#formatted_namesObject



147
148
149
150
151
152
153
154
# File 'lib/outlook2gcal/outlook_calendar.rb', line 147

def formatted_names
  names = "Chair: #{@chair}\nRequired: "
  names += (@required_names || "")
  names += "\nOptional: "+ (@optional_names || "")
  names += "\n---\n"
  #p names
  names 
end

#meeting?Boolean

Returns:

  • (Boolean)


122
123
124
# File 'lib/outlook2gcal/outlook_calendar.rb', line 122

def meeting?
  true # TODO
end

#repeats?Boolean

and (@appointmenttype != :anniversary)

Returns:

  • (Boolean)


130
131
132
# File 'lib/outlook2gcal/outlook_calendar.rb', line 130

def repeats?
  @repeats.size > 1
end

#supported?Boolean

Returns:

  • (Boolean)


126
127
128
129
# File 'lib/outlook2gcal/outlook_calendar.rb', line 126

def supported?
  # anniversaries are now (v.0.0.7) supported 
  @appointmenttype #and (@appointmenttype != :anniversary)
end