class Slacktail::Message

Public Instance Methods

attachments() click to toggle source
# File lib/slacktail/message.rb, line 41
def attachments
  @attachments ||= attachments!
end
channel() click to toggle source
# File lib/slacktail/message.rb, line 5
def channel
  @channel ||= channel!
end
color() click to toggle source
# File lib/slacktail/message.rb, line 13
def color
  if attachments.any?
    attachments.first.color.to_colsole_color
  else
    :rst
  end
end
empty?() click to toggle source
# File lib/slacktail/message.rb, line 25
def empty?
  items.empty?
end
items() click to toggle source
# File lib/slacktail/message.rb, line 21
def items
  @items ||= items!
end
pure_channel() click to toggle source
# File lib/slacktail/message.rb, line 9
def pure_channel
  channel.gsub '#', ''
end
user() click to toggle source
# File lib/slacktail/message.rb, line 29
def user
  result = if data.username
    data.username
  elsif data.user
    client.users[data.user]&.name
  elsif data.bot_id
    client.bots[data.bot_id]&.name
  end

  result || "anonymous"
end

Private Instance Methods

attachments!() click to toggle source
# File lib/slacktail/message.rb, line 61
def attachments!
  return [] unless data.attachments
  data.attachments.map do |attachment| 
    Attachment.new attachment
  end
end
channel!() click to toggle source
# File lib/slacktail/message.rb, line 56
def channel!
  channel = client.channels[data.channel]
  channel ? "##{channel.name}" : "@private"
end
items!() click to toggle source
# File lib/slacktail/message.rb, line 47
def items!
  result = text_lines
  attachments.each do |attachment|
    result += attachment.text_lines
    result += attachment.fields
  end
  result
end