Class: SlackBot::Message
- Inherits:
-
Object
- Object
- SlackBot::Message
- Defined in:
- lib/slack/message.rb
Instance Attribute Summary collapse
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, val) ⇒ Object
- #channel ⇒ Object
-
#id ⇒ Object
Helpers!.
-
#initialize(data, bot) ⇒ Message
constructor
A new instance of Message.
- #reply(text) ⇒ Object
- #text ⇒ Object
- #time ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(data, bot) ⇒ Message
Returns a new instance of Message.
7 8 9 10 11 |
# File 'lib/slack/message.rb', line 7 def initialize(data, bot) @data = data @bot = bot @user = bot.user(data['user']) end |
Instance Attribute Details
#user ⇒ Object (readonly)
Returns the value of attribute user.
5 6 7 |
# File 'lib/slack/message.rb', line 5 def user @user end |
Instance Method Details
#[](key) ⇒ Object
21 22 23 |
# File 'lib/slack/message.rb', line 21 def [](key) @data[key] end |
#[]=(key, val) ⇒ Object
25 26 27 |
# File 'lib/slack/message.rb', line 25 def []=(key, val) @data[key] = val end |
#channel ⇒ Object
36 37 38 39 |
# File 'lib/slack/message.rb', line 36 def channel chan = @data['channel'] @bot.channel chan end |
#id ⇒ Object
Helpers!
30 |
# File 'lib/slack/message.rb', line 30 def id; @data['id'] end |
#reply(text) ⇒ Object
13 14 15 |
# File 'lib/slack/message.rb', line 13 def reply(text) @bot.post channel, text end |
#text ⇒ Object
31 |
# File 'lib/slack/message.rb', line 31 def text; @data['text'] end |
#time ⇒ Object
32 33 34 35 |
# File 'lib/slack/message.rb', line 32 def time ts = @data['ts'] ts && Time.at(ts.to_i) end |
#to_s ⇒ Object
17 18 19 |
# File 'lib/slack/message.rb', line 17 def to_s "#{@user.name}: #{self.text}" end |