Skip to content

Commit

Permalink
Improve message string representation
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosantoniodasilva committed Jan 15, 2011
1 parent fee3d2e commit 69bf95a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/campfire/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,19 @@ def initialize(room, attributes)
@body = attributes["body"]
@created_at = attributes["created_at"]
end

def to_s
%Q[Message #{id}: #{@body} (#{human_type} - #{human_created_at})]
end

private

def human_type
@type.gsub("Message", "")
end

def human_created_at
@created_at.gsub(/ \+.*/, "")
end
end
end
8 changes: 8 additions & 0 deletions test/campfire/message_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,12 @@ def test_initialization
assert_equal "TextMessage", message.type
assert_equal "2011/01/13 01:05:49 +0000", message.created_at
end

def test_string_representation
room = Campfire::Room.new(nil, "id" => "1")
message = Campfire::Message.new(room, "id" => "1",
"type" => "TextMessage", "body" => "Hello!", "created_at" => "2011/01/13 01:05:49 +0000")

assert_equal "Message 1: Hello! (Text - 2011/01/13 01:05:49)", message.to_s
end
end

0 comments on commit 69bf95a

Please sign in to comment.