Class: Slack::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/slack/message.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, attachment = nil) ⇒ Message

Returns a new instance of Message.



6
7
8
9
10
# File 'lib/slack/message.rb', line 6

def initialize(text, attachment = nil)
  @text = text
  @attachments = []
  @attachments << attachment if attachment
end

Instance Attribute Details

#attachmentsObject (readonly)

Returns the value of attribute attachments.



4
5
6
# File 'lib/slack/message.rb', line 4

def attachments
  @attachments
end

#textObject

Returns the value of attribute text.



3
4
5
# File 'lib/slack/message.rb', line 3

def text
  @text
end

Instance Method Details

#add_attachment(attachment) ⇒ Object



12
13
14
# File 'lib/slack/message.rb', line 12

def add_attachment(attachment)
  @attachments << attachment
end

#as_jsonObject



16
17
18
19
20
21
22
# File 'lib/slack/message.rb', line 16

def as_json
  hash = { text: text }

  merge_attachments(hash) unless attachments.empty?

  hash
end