Class: Safubot::XMPP::Message
- Inherits:
-
Object
- Object
- Safubot::XMPP::Message
- Includes:
- MongoMapper::Document
- Defined in:
- lib/safubot/xmpp.rb
Overview
A Message is a Request source representing a single XMPP chat stanza.
Class Method Summary (collapse)
-
+ (Object) from(raw)
Creates a new Message.
Instance Method Summary (collapse)
-
- (Object) make_request
Retrieves or creates an associated Request.
-
- (Object) user
Retrieves the KnownUser associated with this Message.
-
- (Object) username
Retrieves the sender’s username from the JID.
Class Method Details
+ (Object) from(raw)
Creates a new Message.
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/safubot/xmpp.rb', line 44 def from(raw) Message.find_by_xmpp_id(raw.id) || Message.create({ :xml => raw.to_xml, :xmpp_id => raw.id, :text => raw.body.strip, :to => raw.to.to_s, :from => raw.from.to_s }) end |
Instance Method Details
- (Object) make_request
Retrieves or creates an associated Request.
67 68 69 |
# File 'lib/safubot/xmpp.rb', line 67 def make_request self.request || Request.create(:user => user, :source => self, :text => self.text) end |
- (Object) user
Retrieves the KnownUser associated with this Message.
62 63 64 |
# File 'lib/safubot/xmpp.rb', line 62 def user KnownUser.by_xmpp(self.from) end |
- (Object) username
Retrieves the sender’s username from the JID.
57 58 59 |
# File 'lib/safubot/xmpp.rb', line 57 def username self.from.split('@')[0] end |