Class: Slackdraft::Message
Direct Known Subclasses
Instance Method Summary collapse
-
#add_attachment(attachment) ⇒ Object
Add an attachment.
-
#channel ⇒ Object
Set the destination channel.
-
#generate_payload ⇒ Object
Generate the payload if stuff was provided.
-
#icon_emoji ⇒ Object
Set the emoji.
-
#icon_url ⇒ Object
Set the icon URL and default to the emoji.
-
#parse_usernames_and_channels(text) ⇒ Object
Parse username and channels.
-
#text ⇒ Object
Set the text of the message.
-
#username ⇒ Object
Set the api call username.
Methods inherited from Base
Constructor Details
This class inherits a constructor from Slackdraft::Base
Instance Method Details
#add_attachment(attachment) ⇒ Object
Add an attachment
25 26 27 |
# File 'lib/slackdraft/message.rb', line 25 def () self..push(.to_h) end |
#channel ⇒ Object
Set the destination channel
19 20 21 22 |
# File 'lib/slackdraft/message.rb', line 19 def channel return '#general' if @channel.nil? @channel end |
#generate_payload ⇒ Object
Generate the payload if stuff was provided
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/slackdraft/message.rb', line 55 def generate_payload payload = {} payload[:channel] = self.channel unless self.channel.nil? payload[:username] = self.username unless self.username.nil? payload[:icon_url] = self.icon_url unless self.icon_url.nil? payload[:icon_emoji] = self.icon_emoji unless self.icon_emoji.nil? payload[:text] = self.text unless self.text.nil? payload[:attachments] = self. unless self..empty? payload end |
#icon_emoji ⇒ Object
Set the emoji
35 36 37 |
# File 'lib/slackdraft/message.rb', line 35 def icon_emoji return ':fire:' if @icon_emoji.nil? end |
#icon_url ⇒ Object
Set the icon URL and default to the emoji
30 31 32 |
# File 'lib/slackdraft/message.rb', line 30 def icon_url @icon_url || icon_emoji end |
#parse_usernames_and_channels(text) ⇒ Object
Parse username and channels
40 41 42 |
# File 'lib/slackdraft/message.rb', line 40 def parse_usernames_and_channels(text) text.gsub(/(@\w+)/, '<\1>').gsub(/(#\w+)/, '<\1>') end |
#text ⇒ Object
Set the text of the message
45 46 47 48 49 50 51 52 |
# File 'lib/slackdraft/message.rb', line 45 def text if @text.kind_of?(Array) return parse_usernames_and_channels(@text.join("\n")) end parse_usernames_and_channels(@text) end |
#username ⇒ Object
Set the api call username
13 14 15 16 |
# File 'lib/slackdraft/message.rb', line 13 def username return 'slackdraft' if @username.nil? @username end |