Class: Lita::Source
- Inherits:
-
Object
- Object
- Lita::Source
- Defined in:
- lib/lita/source.rb
Overview
A wrapper object representing the source of an incoming message (either the user who sent it, the room they sent it from, or both). If a room is set, the message is from a group chat room. If no room is set, the message is assumed to be a private message, though Source objects can be explicitly marked as private messages. Source objects are also used as “target” objects when sending an outgoing message or performing another operation on a user or a room.
Instance Attribute Summary collapse
-
#private_message ⇒ Boolean
(also: #private_message?)
readonly
A flag indicating that a message was sent to the robot privately.
-
#room ⇒ String, NilClass
readonly
The room the message came from or should be sent to, as a string.
-
#room_object ⇒ Lita::Room, NilClass
readonly
The room the message came from or should be sent to, as a Room object.
-
#user ⇒ Lita::User, NilClass
readonly
The user who sent the message or should receive the outgoing message.
Instance Method Summary collapse
-
#initialize(user: nil, room: nil, private_message: false) ⇒ Source
constructor
A new instance of Source.
-
#private_message! ⇒ void
Destructively marks the source as a private message, meaning an incoming message was sent to the robot privately, or an outgoing message should be sent to a user privately.
Constructor Details
#initialize(user: nil, room: nil, private_message: false) ⇒ Source
Returns a new instance of Source.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/lita/source.rb', line 35 def initialize(user: nil, room: nil, private_message: false) @user = user case room when String @room = room @room_object = Room.new(room) when Room @room = room.id @room_object = room end = raise ArgumentError, I18n.t("lita.source.user_or_room_required") if user.nil? && room.nil? = true if room.nil? end |
Instance Attribute Details
#private_message ⇒ Boolean (readonly) Also known as: private_message?
A flag indicating that a message was sent to the robot privately.
12 13 14 |
# File 'lib/lita/source.rb', line 12 def end |
#room ⇒ String, NilClass (readonly)
The room the message came from or should be sent to, as a string.
17 18 19 |
# File 'lib/lita/source.rb', line 17 def room @room end |
#room_object ⇒ Lita::Room, NilClass (readonly)
The room the message came from or should be sent to, as a Room object.
22 23 24 |
# File 'lib/lita/source.rb', line 22 def room_object @room_object end |
#user ⇒ Lita::User, NilClass (readonly)
The user who sent the message or should receive the outgoing message.
26 27 28 |
# File 'lib/lita/source.rb', line 26 def user @user end |
Instance Method Details
#private_message! ⇒ void
This method returns an undefined value.
Destructively marks the source as a private message, meaning an incoming message was sent to the robot privately, or an outgoing message should be sent to a user privately.
58 59 60 |
# File 'lib/lita/source.rb', line 58 def = true end |