class Slack::Attachment

Constants

ATTRIBUTES

Attributes

fields[R]

Public Class Methods

new(options = {}) click to toggle source
# File lib/slack/attachment.rb, line 16
def initialize(options = {})
  @fields = []

  ATTRIBUTES.each do |attribute|
    send("#{attribute}=", options.delete(attribute))
  end
end

Public Instance Methods

add_field(title, value, short = false) click to toggle source
# File lib/slack/attachment.rb, line 24
def add_field(title, value, short = false)
  fields << Field.new(title, value, short)
end
as_json() click to toggle source
# 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] = author.as_json if author

  hash
end