Class: CampfireExport::Message
- Inherits:
-
Object
- Object
- CampfireExport::Message
- Includes:
- IO
- Defined in:
- lib/campfire_export.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#date ⇒ Object
Returns the value of attribute date.
-
#id ⇒ Object
Returns the value of attribute id.
-
#room ⇒ Object
Returns the value of attribute room.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
-
#type ⇒ Object
Returns the value of attribute type.
-
#upload ⇒ Object
Returns the value of attribute upload.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #indent(string, count) ⇒ Object
-
#initialize(message, room, date) ⇒ Message
constructor
A new instance of Message.
- #is_upload? ⇒ Boolean
- #to_s ⇒ Object
- #username(user_id) ⇒ Object
Methods included from IO
#api_url, #export_dir, #export_file, #get, #log, #verify_export, #zero_pad
Constructor Details
#initialize(message, room, date) ⇒ Message
Returns a new instance of Message.
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/campfire_export.rb', line 303 def initialize(, room, date) @id = .xpath('id').text @room = room @date = date @body = .xpath('body').text @type = .xpath('type').text time = Time.parse .xpath('created-at').text localtime = CampfireExport::Account.timezone.utc_to_local(time) @timestamp = localtime.strftime '%I:%M %p' no_user = ['TimestampMessage', 'SystemMessage', 'AdvertisementMessage'] unless no_user.include?(@type) @user = username(.xpath('user-id').text) end @upload = CampfireExport::Upload.new(self) if is_upload? end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
301 302 303 |
# File 'lib/campfire_export.rb', line 301 def body @body end |
#date ⇒ Object
Returns the value of attribute date.
301 302 303 |
# File 'lib/campfire_export.rb', line 301 def date @date end |
#id ⇒ Object
Returns the value of attribute id.
301 302 303 |
# File 'lib/campfire_export.rb', line 301 def id @id end |
#room ⇒ Object
Returns the value of attribute room.
301 302 303 |
# File 'lib/campfire_export.rb', line 301 def room @room end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
301 302 303 |
# File 'lib/campfire_export.rb', line 301 def @timestamp end |
#type ⇒ Object
Returns the value of attribute type.
301 302 303 |
# File 'lib/campfire_export.rb', line 301 def type @type end |
#upload ⇒ Object
Returns the value of attribute upload.
301 302 303 |
# File 'lib/campfire_export.rb', line 301 def upload @upload end |
#user ⇒ Object
Returns the value of attribute user.
301 302 303 |
# File 'lib/campfire_export.rb', line 301 def user @user end |
Instance Method Details
#indent(string, count) ⇒ Object
344 345 346 |
# File 'lib/campfire_export.rb', line 344 def indent(string, count) (' ' * count) + string.gsub(/(\n+)/) { $1 + (' ' * count) } end |
#is_upload? ⇒ Boolean
340 341 342 |
# File 'lib/campfire_export.rb', line 340 def is_upload? @type == 'UploadMessage' end |
#to_s ⇒ Object
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 |
# File 'lib/campfire_export.rb', line 348 def to_s case type when 'EnterMessage' "[#{user} has entered the room]\n" when 'KickMessage', 'LeaveMessage' "[#{user} has left the room]\n" when 'TextMessage' "[#{user.rjust(12)}:] #{body}\n" when 'UploadMessage' "[#{user} uploaded: #{body}]\n" when 'PasteMessage' "[" + "#{user} pasted:]".rjust(14) + "\n#{indent(body, 16)}\n" when 'TopicChangeMessage' "[#{user} changed the topic to: #{body}]\n" when 'ConferenceCreatedMessage' "[#{user} created conference: #{body}]\n" when 'AllowGuestsMessage' "[#{user} opened the room to guests]\n" when 'DisallowGuestsMessage' "[#{user} closed the room to guests]\n" when 'LockMessage' "[#{user} locked the room]\n" when 'UnlockMessage' "[#{user} unlocked the room]\n" when 'IdleMessage' "[#{user} became idle]\n" when 'UnidleMessage' "[#{user} became active]\n" when 'TweetMessage' "[#{user} tweeted:] #{body}\n" when 'SoundMessage' "[#{user} played a sound:] #{body}\n" when 'TimestampMessage' "--- #{} ---\n" when 'SystemMessage' "" when 'AdvertisementMessage' "" else log(:error, "unknown message type: #{type} - '#{body}'") "" end end |
#username(user_id) ⇒ Object
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
# File 'lib/campfire_export.rb', line 322 def username(user_id) @@usernames ||= {} @@usernames[user_id] ||= begin doc = Nokogiri::XML get("/users/#{user_id}.xml").body rescue Exception => e "[unknown user]" else # Take the first name and last initial, if there is more than one name. name_parts = doc.xpath('/user/name').text.split if name_parts.length > 1 name_parts[-1] = "#{name_parts.last[0,1]}." name_parts.join(" ") else name_parts[0] end end end |