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.



8
9
10
11
12
# File 'lib/slack/message.rb', line 8

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

Instance Attribute Details

#attachmentsObject (readonly)

Returns the value of attribute attachments.



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

def attachments
  @attachments
end

#textObject

Returns the value of attribute text.



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

def text
  @text
end

Instance Method Details

#add_attachment(attachment) ⇒ Object



14
15
16
# File 'lib/slack/message.rb', line 14

def add_attachment(attachment)
  @attachments << attachment
end

#as_jsonObject



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

def as_json
  hash = { text: text }

  merge_attachments(hash) unless attachments.empty?

  hash
end