Class: CampfireExport::Transcript
- Inherits:
-
Object
- Object
- CampfireExport::Transcript
- Includes:
- IO
- Defined in:
- lib/campfire_export.rb
Instance Attribute Summary collapse
-
#date ⇒ Object
Returns the value of attribute date.
-
#messages ⇒ Object
Returns the value of attribute messages.
-
#room ⇒ Object
Returns the value of attribute room.
-
#xml ⇒ Object
Returns the value of attribute xml.
Instance Method Summary collapse
- #export ⇒ Object
- #export_html ⇒ Object
- #export_plaintext ⇒ Object
- #export_uploads ⇒ Object
- #export_xml ⇒ Object
-
#initialize(room, date) ⇒ Transcript
constructor
A new instance of Transcript.
- #transcript_path ⇒ Object
Methods included from IO
#api_url, #export_dir, #export_file, #get, #log, #verify_export, #zero_pad
Constructor Details
#initialize(room, date) ⇒ Transcript
Returns a new instance of Transcript.
204 205 206 207 |
# File 'lib/campfire_export.rb', line 204 def initialize(room, date) @room = room @date = date end |
Instance Attribute Details
#date ⇒ Object
Returns the value of attribute date.
202 203 204 |
# File 'lib/campfire_export.rb', line 202 def date @date end |
#messages ⇒ Object
Returns the value of attribute messages.
202 203 204 |
# File 'lib/campfire_export.rb', line 202 def @messages end |
#room ⇒ Object
Returns the value of attribute room.
202 203 204 |
# File 'lib/campfire_export.rb', line 202 def room @room end |
#xml ⇒ Object
Returns the value of attribute xml.
202 203 204 |
# File 'lib/campfire_export.rb', line 202 def xml @xml end |
Instance Method Details
#export ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/campfire_export.rb', line 213 def export begin log(:info, "#{export_dir} ... ") @xml = Nokogiri::XML get("#{transcript_path}.xml").body rescue Exception => e log(:error, "transcript export for #{export_dir} failed", e) else @messages = xml.xpath('/messages/message').map do || CampfireExport::Message.new(, room, date) end # Only export transcripts that contain at least one message. if .length > 0 log(:info, "exporting transcripts\n") begin FileUtils.mkdir_p export_dir rescue Exception => e log(:error, "Unable to create #{export_dir}", e) else export_xml export_plaintext export_html export_uploads end else log(:info, "no messages\n") end end end |
#export_html ⇒ Object
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/campfire_export.rb', line 265 def export_html begin transcript_html = get(transcript_path) # Make the upload links in the transcript clickable from the exported # directory layout. transcript_html.gsub!(%Q{href="/room/#{room.id}/uploads/}, %Q{href="uploads/}) # Likewise, make the image thumbnails embeddable from the exported # directory layout. transcript_html.gsub!(%Q{src="/room/#{room.id}/thumb/}, %Q{src="thumbs/}) export_file(transcript_html, 'transcript.html') verify_export('transcript.html', transcript_html.length) rescue Exception => e log(:error, "HTML transcript export for #{export_dir} failed", e) end end |
#export_plaintext ⇒ Object
252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/campfire_export.rb', line 252 def export_plaintext begin date_header = date.strftime('%A, %B %e, %Y').squeeze(" ") plaintext = "#{CampfireExport::Account.subdomain.upcase} CAMPFIRE\n" plaintext << "#{room.name}: #{date_header}\n\n" .each {|| plaintext << .to_s } export_file(plaintext, 'transcript.txt') verify_export('transcript.txt', plaintext.length) rescue Exception => e log(:error, "Plaintext transcript export for #{export_dir} failed", e) end end |
#export_uploads ⇒ Object
285 286 287 288 289 290 291 292 293 294 295 296 |
# File 'lib/campfire_export.rb', line 285 def export_uploads .each do || if .is_upload? begin .upload.export rescue Exception => e path = "#{.upload.export_dir}/#{.upload.filename}" log(:error, "Upload export for #{path} failed", e) end end end end |
#export_xml ⇒ Object
243 244 245 246 247 248 249 250 |
# File 'lib/campfire_export.rb', line 243 def export_xml begin export_file(xml, 'transcript.xml') verify_export('transcript.xml', xml.to_s.length) rescue Exception => e log(:error, "XML transcript export for #{export_dir} failed", e) end end |
#transcript_path ⇒ Object
209 210 211 |
# File 'lib/campfire_export.rb', line 209 def transcript_path "/room/#{room.id}/transcript/#{date.year}/#{date.mon}/#{date.mday}" end |