Class: NCal2GCal::LotusNotesEvent
- Inherits:
-
Object
- Object
- NCal2GCal::LotusNotesEvent
- Defined in:
- lib/ncal2gcal/lotus_notes_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
- #all_day? ⇒ Boolean
- #all_names ⇒ Object
- #fill_alarm(notes_event) ⇒ Object
- #fill_chair(notes_event) ⇒ Object
- #fill_names(notes_event) ⇒ Object
- #fill_notes_names(notes_event, notes_attr_name, notes_attr_email = nil) ⇒ Object
- #fill_repeats(notes_event) ⇒ Object
- #find_email(names, idx) ⇒ Object
- #formatted_names ⇒ Object
-
#initialize(notes_event) ⇒ LotusNotesEvent
constructor
A new instance of LotusNotesEvent.
- #meeting? ⇒ Boolean
- #names_to_str(names) ⇒ Object
- #names_to_str_name_email(names) ⇒ Object
-
#repeats? ⇒ Boolean
and (@appointmenttype != :anniversary).
- #supported? ⇒ Boolean
Constructor Details
#initialize(notes_event) ⇒ LotusNotesEvent
Returns a new instance of LotusNotesEvent.
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 119 120 121 122 123 |
# File 'lib/ncal2gcal/lotus_notes_calendar.rb', line 81 def initialize(notes_event) fill_alarm(notes_event) # Notes Id @uid = notes_event.UniversalID # Subject if notes_event.GetFirstItem("Subject") @subject = notes_event.GetFirstItem("Subject").Values[0] else @subject = '' $logger.warn 'no subject. uid: '+@uid end # if notes_event.GetFirstItem("ROOM") @where = notes_event.GetFirstItem("ROOM").Values[0] elsif notes_event.GetFirstItem("Location") @where = notes_event.GetFirstItem("Location").Values[0] else @where = '' end # start date + time @start_time = notes_event.GetFirstItem("Startdatetime").Values[0] if notes_event.GetFirstItem("Startdatetime") # end date + time @end_time = notes_event.GetFirstItem("EndDatetime").Values[0] if notes_event.GetFirstItem("EndDatetime") # event type if notes_event.GetFirstItem("APPOINTMENTTYPE") @appointmenttype = APPOINTMENTTYPE[notes_event.GetFirstItem("APPOINTMENTTYPE").Values[0]] end @last_modified = DateTime.parse(notes_event.LastModified) @content = '' body = notes_event.GetFirstItem("Body") if body @content = body.Values unless body.Values.is_a? Array end fill_repeats(notes_event) fill_names(notes_event) if meeting? end |
Instance Method Details
#all_day? ⇒ Boolean
124 125 126 |
# File 'lib/ncal2gcal/lotus_notes_calendar.rb', line 124 def all_day? @appointmenttype and (@appointmenttype == :all_day_event or @appointmenttype == :anniversary) end |
#all_names ⇒ Object
210 211 212 213 214 215 216 217 |
# File 'lib/ncal2gcal/lotus_notes_calendar.rb', line 210 def all_names names = [] names += @chair || [] names += @required_names || [] names += @optional_names || [] names.uniq end |
#fill_alarm(notes_event) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/ncal2gcal/lotus_notes_calendar.rb', line 138 def fill_alarm(notes_event) # Alarm @alarm = false @alarm_offset = 0 if notes_event.GetFirstItem("$Alarm") then if notes_event.GetFirstItem("$Alarm").Values[0] == 1.0 then @alarm = true ao = notes_event.GetFirstItem("$AlarmOffset") if ao aov = ao.Values[0].to_i if aov > -GCAL_MIN_REMINDER aov = GCAL_MIN_REMINDER elsif aov < -GCAL_MAX_REMINDER aov = GCAL_MAX_REMINDER end @alarm_offset = aov.abs end end end end |
#fill_chair(notes_event) ⇒ Object
223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/ncal2gcal/lotus_notes_calendar.rb', line 223 def fill_chair(notes_event) chair = [] notes_chair = notes_event.GetFirstItem("CHAIR") notes_chair = notes_event.GetFirstItem('AltChair') unless notes_chair if notes_chair then notes_chair.Values.each do |name| name =~ /^CN=(.*)\/O=(.*)\/C=(.*)/ chair << {:name => ($1 || name)} end end chair end |
#fill_names(notes_event) ⇒ Object
218 219 220 221 222 |
# File 'lib/ncal2gcal/lotus_notes_calendar.rb', line 218 def fill_names(notes_event) @chair = fill_chair(notes_event) @required_names = fill_notes_names(notes_event, 'AltRequiredNames', 'INetRequiredNames') @optional_names = fill_notes_names(notes_event, 'AltOptionalNames', 'INetOptionalNames') end |
#fill_notes_names(notes_event, notes_attr_name, notes_attr_email = nil) ⇒ Object
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/ncal2gcal/lotus_notes_calendar.rb', line 247 def fill_notes_names(notes_event, notes_attr_name, notes_attr_email = nil) names = [] notes_names = [] notes_names1 = notes_event.GetFirstItem(notes_attr_name) if notes_attr_email notes_names2 = notes_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 |
#fill_repeats(notes_event) ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/ncal2gcal/lotus_notes_calendar.rb', line 161 def fill_repeats(notes_event) @repeats = [] sdts = notes_event.GetFirstItem("Startdatetime") edts = notes_event.GetFirstItem("EndDatetime") return unless sdts sdts.Values.each_with_index do |val, idx | r = EventRepeat.new r.start_time = val if edts r.end_time = edts.Values[idx] else $logger.warn "EndDatetime default" $logger.warn @subject $logger.warn r.start_time r.end_time = r.start_time end @repeats << r end end |
#find_email(names, idx) ⇒ Object
236 237 238 239 240 241 242 243 244 245 |
# File 'lib/ncal2gcal/lotus_notes_calendar.rb', line 236 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 |
#formatted_names ⇒ Object
181 182 183 184 185 186 187 188 |
# File 'lib/ncal2gcal/lotus_notes_calendar.rb', line 181 def formatted_names names = "Chair: #{names_to_str(@chair)}\nRequired: " names += names_to_str_name_email(@required_names) names += "\nOptional: "+names_to_str_name_email(@optional_names) names += "\n---\n" #p names names end |
#meeting? ⇒ Boolean
127 128 129 |
# File 'lib/ncal2gcal/lotus_notes_calendar.rb', line 127 def meeting? @appointmenttype and (@appointmenttype == :meeting) end |
#names_to_str(names) ⇒ Object
200 201 202 203 204 205 206 207 208 209 |
# File 'lib/ncal2gcal/lotus_notes_calendar.rb', line 200 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
189 190 191 192 193 194 195 196 197 198 |
# File 'lib/ncal2gcal/lotus_notes_calendar.rb', line 189 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 |
#repeats? ⇒ Boolean
and (@appointmenttype != :anniversary)
135 136 137 |
# File 'lib/ncal2gcal/lotus_notes_calendar.rb', line 135 def repeats? @repeats.size > 1 end |
#supported? ⇒ Boolean
131 132 133 134 |
# File 'lib/ncal2gcal/lotus_notes_calendar.rb', line 131 def supported? # anniversaries are now (v.0.0.7) supported @appointmenttype #and (@appointmenttype != :anniversary) end |