Class: Sinatra::Slack::Helpers::Attachment
- Inherits:
-
Object
- Object
- Sinatra::Slack::Helpers::Attachment
- Defined in:
- lib/sinatra/slack/helpers/slack_attachment.rb
Overview
Represents a message attachment sent to the Slack Channel.
Instance Attribute Summary collapse
-
#attachment_type ⇒ Object
Returns the value of attribute attachment_type.
-
#color ⇒ Object
Returns the value of attribute color.
-
#fallback ⇒ Object
Returns the value of attribute fallback.
-
#image_url ⇒ Object
Returns the value of attribute image_url.
-
#text ⇒ Object
Returns the value of attribute text.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #action_button(name, text, value) ⇒ Object
- #action_menu(name, text, options) ⇒ Object
-
#initialize(callback_id) ⇒ Attachment
constructor
A new instance of Attachment.
- #to_json ⇒ Object
Constructor Details
#initialize(callback_id) ⇒ Attachment
Returns a new instance of Attachment.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/sinatra/slack/helpers/slack_attachment.rb', line 11 def initialize(callback_id) @callback_id = callback_id = 'default' @color = '#3AA3E3' @actions = [] @text = '' @fallback = '' @image_url = '' @title = '' end |
Instance Attribute Details
#attachment_type ⇒ Object
Returns the value of attribute attachment_type.
8 9 10 |
# File 'lib/sinatra/slack/helpers/slack_attachment.rb', line 8 def end |
#color ⇒ Object
Returns the value of attribute color.
8 9 10 |
# File 'lib/sinatra/slack/helpers/slack_attachment.rb', line 8 def color @color end |
#fallback ⇒ Object
Returns the value of attribute fallback.
8 9 10 |
# File 'lib/sinatra/slack/helpers/slack_attachment.rb', line 8 def fallback @fallback end |
#image_url ⇒ Object
Returns the value of attribute image_url.
8 9 10 |
# File 'lib/sinatra/slack/helpers/slack_attachment.rb', line 8 def image_url @image_url end |
#text ⇒ Object
Returns the value of attribute text.
8 9 10 |
# File 'lib/sinatra/slack/helpers/slack_attachment.rb', line 8 def text @text end |
#title ⇒ Object
Returns the value of attribute title.
8 9 10 |
# File 'lib/sinatra/slack/helpers/slack_attachment.rb', line 8 def title @title end |
Instance Method Details
#action_button(name, text, value) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/sinatra/slack/helpers/slack_attachment.rb', line 23 def (name, text, value) @actions << { name: name, text: text, type: 'button', value: value } end |
#action_menu(name, text, options) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/sinatra/slack/helpers/slack_attachment.rb', line 32 def (name, text, ) @actions << { name: name, text: text, type: 'select', options: } end |
#to_json ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/sinatra/slack/helpers/slack_attachment.rb', line 41 def to_json att_obj = {} att_obj[:callback_id] = @callback_id att_obj[:title] = title unless title.empty? att_obj[:color] = color unless color.empty? att_obj[:attachment_type] = unless .empty? att_obj[:text] = text unless text.empty? att_obj[:fallback] = fallback unless fallback.empty? att_obj[:image_url] = image_url unless image_url.empty? att_obj[:actions] = @actions unless @actions.empty? att_obj end |