Class: MeshChat::Message::Base
- Inherits:
-
Object
- Object
- MeshChat::Message::Base
- Defined in:
- lib/meshchat/message/base.rb
Overview
NOTE:
#display: shows the message
should be used locally, before *sending* a message
#handle: processing logic for the message
should be used when receiving a message, and there
needs to be a response right away
#respond: where the actual logic for the response goes
Direct Known Subclasses
Chat, Disconnection, NodeList, NodeListDiff, NodeListHash, Ping, PingReply, Relay, Whisper
Instance Attribute Summary collapse
-
#message ⇒ Object
Returns the value of attribute message.
-
#payload ⇒ Object
Returns the value of attribute payload.
-
#sender_location ⇒ Object
Returns the value of attribute sender_location.
-
#sender_name ⇒ Object
Returns the value of attribute sender_name.
-
#sender_uid ⇒ Object
Returns the value of attribute sender_uid.
-
#time_recieved ⇒ Object
Returns the value of attribute time_recieved.
Instance Method Summary collapse
- #client ⇒ Object
- #client_version ⇒ Object
-
#display ⇒ Object
shows the message should be used locally, before sending a message.
-
#handle ⇒ Object
processing logic for the message should be used when receiving a message, and there needs to be a response right away.
-
#initialize(message: '', sender_name: '', sender_location: '', sender_uid: '', time_recieved: nil, payload: nil) ⇒ Base
constructor
A new instance of Base.
-
#render ⇒ Object
this message should be called immediately before sending to the whomever.
-
#respond ⇒ Object
Most message types aren’t going to need to have an immediate response.
- #type ⇒ Object
Constructor Details
#initialize(message: '', sender_name: '', sender_location: '', sender_uid: '', time_recieved: nil, payload: nil) ⇒ Base
Returns a new instance of Base.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/meshchat/message/base.rb', line 19 def initialize( message: '', sender_name: '', sender_location: '', sender_uid: '', time_recieved: nil, payload: nil) @payload = payload.presence # TODO: find a more elegant way to represent this self. = .presence || @payload.try(:[], 'message') self.sender_name = sender_name.presence || @payload.try(:[], 'sender').try(:[], 'alias') || Settings['alias'] self.sender_location = sender_location.presence || @payload.try(:[], 'sender').try(:[], 'location') || Settings.location self.sender_uid = sender_uid.presence || @payload.try(:[], 'sender').try(:[], 'uid') || Settings['uid'] self.time_recieved = time_recieved.presence || Time.now end |
Instance Attribute Details
#message ⇒ Object
Returns the value of attribute message.
12 13 14 |
# File 'lib/meshchat/message/base.rb', line 12 def @message end |
#payload ⇒ Object
Returns the value of attribute payload.
12 13 14 |
# File 'lib/meshchat/message/base.rb', line 12 def payload @payload end |
#sender_location ⇒ Object
Returns the value of attribute sender_location.
12 13 14 |
# File 'lib/meshchat/message/base.rb', line 12 def sender_location @sender_location end |
#sender_name ⇒ Object
Returns the value of attribute sender_name.
12 13 14 |
# File 'lib/meshchat/message/base.rb', line 12 def sender_name @sender_name end |
#sender_uid ⇒ Object
Returns the value of attribute sender_uid.
12 13 14 |
# File 'lib/meshchat/message/base.rb', line 12 def sender_uid @sender_uid end |
#time_recieved ⇒ Object
Returns the value of attribute time_recieved.
12 13 14 |
# File 'lib/meshchat/message/base.rb', line 12 def time_recieved @time_recieved end |
Instance Method Details
#client ⇒ Object
57 58 59 |
# File 'lib/meshchat/message/base.rb', line 57 def client MeshChat.name end |
#client_version ⇒ Object
61 62 63 |
# File 'lib/meshchat/message/base.rb', line 61 def client_version MeshChat.version end |
#display ⇒ Object
shows the message should be used locally, before sending a message
67 68 69 |
# File 'lib/meshchat/message/base.rb', line 67 def display end |
#handle ⇒ Object
processing logic for the message should be used when receiving a message, and there needs to be a response right away. this may call display, if the response is always to be displayed
75 76 77 |
# File 'lib/meshchat/message/base.rb', line 75 def handle display end |
#render ⇒ Object
this message should be called immediately before sending to the whomever
88 89 90 |
# File 'lib/meshchat/message/base.rb', line 88 def render payload.to_json end |
#respond ⇒ Object
Most message types aren’t going to need to have an immediate response.
82 83 84 |
# File 'lib/meshchat/message/base.rb', line 82 def respond return end |
#type ⇒ Object
53 54 55 |
# File 'lib/meshchat/message/base.rb', line 53 def type @type ||= TYPES.invert[self.class] end |