Class: Slack::Attachment
- Inherits:
-
Object
- Object
- Slack::Attachment
- Defined in:
- lib/slack/attachment.rb
Constant Summary collapse
- ATTRIBUTES =
%i[ fallback text title title_link image_url thumb_url color pretext author author_name author_link author_icon ].freeze
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
Instance Method Summary collapse
- #add_field(title, value, short = false) ⇒ Object
- #as_json ⇒ Object
-
#initialize(options = {}) ⇒ Attachment
constructor
A new instance of Attachment.
Constructor Details
#initialize(options = {}) ⇒ Attachment
Returns a new instance of Attachment.
16 17 18 19 20 21 22 |
# File 'lib/slack/attachment.rb', line 16 def initialize( = {}) @fields = [] ATTRIBUTES.each do |attribute| send("#{attribute}=", .delete(attribute)) end end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
14 15 16 |
# File 'lib/slack/attachment.rb', line 14 def fields @fields end |
Instance Method Details
#add_field(title, value, short = false) ⇒ Object
24 25 26 |
# File 'lib/slack/attachment.rb', line 24 def add_field(title, value, short = false) fields << Field.new(title, value, short) end |
#as_json ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/slack/attachment.rb', line 28 def as_json hash = {} ATTRIBUTES.each do |attribute| hash[attribute] = send(attribute) if send(attribute) end hash[:fields] = fields.map(&:as_json) unless fields.empty? hash[:author] = .as_json if hash end |