class Discord::Embed

Attributes

data[R]

Public Class Methods

new(&block) click to toggle source
# File lib/discord_notifier/embed.rb, line 5
def initialize(&block)
  @data = {}
  self.instance_exec(&block) if block_given?
end

Public Instance Methods

add_field(params) click to toggle source
# File lib/discord_notifier/embed.rb, line 78
def add_field(params)
  raise ArgumentError, "Field Embed data must be a Hash" unless params.is_a?(Hash)

  @data[:fields] ||= []
  @data[:fields] << params
end
Also aliased as: field
author(params) click to toggle source
# File lib/discord_notifier/embed.rb, line 66
def author(params)
  raise ArgumentError, "Author Embed data must be a Hash" unless params.is_a?(Hash)

  @data[:author] = params
end
color(val) click to toggle source
# File lib/discord_notifier/embed.rb, line 30
def color(val)
  case val
  when String
    @data[:color] = val.delete('#').to_i(16)
  when Integer
    raise ArgumentError, 'Color must be 24 bit' if val >= 16_777_216
    @data[:color] = val
  else
    raise ArgumentError, 'Color must be hex or 24 bit int'
  end
end
description(str) click to toggle source
# File lib/discord_notifier/embed.rb, line 15
def description(str)
  raise ArgumentError, 'Description Embed data must be a String' unless str.is_a?(String)
  @data[:description] = str
end
field(params)
Alias for: add_field
image(params) click to toggle source
# File lib/discord_notifier/embed.rb, line 54
def image(params)
  raise ArgumentError, "Image Embed data must be a Hash" unless params.is_a?(Hash)

  @data[:image] = params
end
provider(params) click to toggle source
# File lib/discord_notifier/embed.rb, line 60
def provider(params)
  raise ArgumentError, "Provider Embed data must be a Hash" unless params.is_a?(Hash)

  @data[:provider] = params
end
thumbnail(params) click to toggle source
# File lib/discord_notifier/embed.rb, line 42
def thumbnail(params)
  raise ArgumentError, "Thumbnail Embed data must be a Hash" unless params.is_a?(Hash)

  @data[:thumbnail] = params
end
timestamp(date) click to toggle source
# File lib/discord_notifier/embed.rb, line 25
def timestamp(date)
  raise ArgumentError, 'Timestamp Embed data must be a Date' unless date.is_a?(DateTime)
  @data[:timestamp] = date
end
title(str) click to toggle source
# File lib/discord_notifier/embed.rb, line 10
def title(str)
  raise ArgumentError, 'Title Embed data must be a String' unless str.is_a?(String)
  @data[:title] = str
end
url(str) click to toggle source
# File lib/discord_notifier/embed.rb, line 20
def url(str)
  raise ArgumentError, 'URL Embed data must be a String' unless str.is_a?(String)
  @data[:url] = str
end
video(params) click to toggle source
# File lib/discord_notifier/embed.rb, line 48
def video(params)
  raise ArgumentError, "Video Embed data must be a Hash" unless params.is_a?(Hash)

  @data[:video] = params
end