Class: Jabbot::Message

Inherits:
Struct
  • Object
show all
Defined in:
lib/jabbot/bot.rb

Overview

A message consists of the username, the text, a time when it was received and the type of the message.

The type could be one Symbol of:

* :public
* :private
* :join
* :leave
* :subject

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#textObject

Returns the value of attribute text

Returns:

  • (Object)

    the current value of text



19
20
21
# File 'lib/jabbot/bot.rb', line 19

def text
  @text
end

#timeObject

Returns the value of attribute time

Returns:

  • (Object)

    the current value of time



19
20
21
# File 'lib/jabbot/bot.rb', line 19

def time
  @time
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



19
20
21
# File 'lib/jabbot/bot.rb', line 19

def type
  @type
end

#userObject

Returns the value of attribute user

Returns:

  • (Object)

    the current value of user



19
20
21
# File 'lib/jabbot/bot.rb', line 19

def user
  @user
end

Instance Method Details

#to_json(*a) ⇒ Object

Public: Encode a message in JSON

Returns the json-ified String of the Hash representation of this message.



30
31
32
33
34
35
36
37
# File 'lib/jabbot/bot.rb', line 30

def to_json(*a)
  {
    :user => user,
    :text => text,
    :time => time,
    :type => type
  }.to_json(*a)
end

#to_sObject

Public: Converts the message to printable text.

Returns a String containing the user’s name and the text.



23
24
25
# File 'lib/jabbot/bot.rb', line 23

def to_s
  "#{user}: #{text}"
end