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
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'lib/campfire_export.rb', line 304 def initialize(, room, date) @id = .css('id').text @room = room @date = date @body = .css('body').text @type = .css('type').text time = Time.parse .css('created-at').text localtime = CampfireExport::Account.timezone.utc_to_local(time) = localtime.strftime '%I:%M %p' no_user = ['TimestampMessage', 'SystemMessage', 'AdvertisementMessage'] unless no_user.include?(@type) @user = username(.css('user-id').text) end @upload = CampfireExport::Upload.new(self) if is_upload? end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
302 303 304 |
# File 'lib/campfire_export.rb', line 302 def body @body end |
#date ⇒ Object
Returns the value of attribute date.
302 303 304 |
# File 'lib/campfire_export.rb', line 302 def date @date end |
#id ⇒ Object
Returns the value of attribute id.
302 303 304 |
# File 'lib/campfire_export.rb', line 302 def id @id end |
#room ⇒ Object
Returns the value of attribute room.
302 303 304 |
# File 'lib/campfire_export.rb', line 302 def room @room end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
302 303 304 |
# File 'lib/campfire_export.rb', line 302 def end |
#type ⇒ Object
Returns the value of attribute type.
302 303 304 |
# File 'lib/campfire_export.rb', line 302 def type @type end |
#upload ⇒ Object
Returns the value of attribute upload.
302 303 304 |
# File 'lib/campfire_export.rb', line 302 def upload @upload end |
#user ⇒ Object
Returns the value of attribute user.
302 303 304 |
# File 'lib/campfire_export.rb', line 302 def user @user end |
Instance Method Details
#indent(string, count) ⇒ Object
345 346 347 |
# File 'lib/campfire_export.rb', line 345 def indent(string, count) (' ' * count) + string.gsub(/(\n+)/) { $1 + (' ' * count) } end |
#is_upload? ⇒ Boolean
341 342 343 |
# File 'lib/campfire_export.rb', line 341 def is_upload? @type == 'UploadMessage' end |
#to_s ⇒ Object
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 391 |
# File 'lib/campfire_export.rb', line 349 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' "--- #{timestamp} ---\n" when 'SystemMessage' "" when 'AdvertisementMessage' "" else log(:error, "unknown message type: #{type} - '#{body}'") "" end end |
#username(user_id) ⇒ Object
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
# File 'lib/campfire_export.rb', line 323 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.css('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 |