class Discorb::Embed
Represents an embed of discord.
Attributes
@return [Discorb::Color, nil] The color of embed.
@return [String, nil] The description of embed.
@return [Array<Discorb::Embed::Field>] The fields of embed.
@return [Time, nil] The timestamp of embed.
@return [String, nil] The title of embed.
@return [Symbol] The type of embed.
@return [String, nil] The url of embed.
Public Class Methods
Initialize a new Embed
object.
@param [String] title The title of embed. @param [String] description The description of embed. @param [Discorb::Color] color The color of embed. @param [String] url The url of embed. @param [Time] timestamp The timestamp of embed. @param [Discorb::Embed::Author] author The author field of embed. @param [Array<Discorb::Embed::Field>] fields The fields of embed. @param [Discorb::Embed::Footer] footer The footer of embed. @param [Discorb::Embed::Image, String] image The image of embed. @param [Discorb::Embed::Thumbnail, String] thumbnail The thumbnail of embed.
# File lib/discorb/embed.rb, line 47 def initialize(title = nil, description = nil, color: nil, url: nil, timestamp: nil, author: nil, fields: nil, footer: nil, image: nil, thumbnail: nil, data: nil) if data.nil? @title = title @description = description @url = url @timestamp = timestamp @color = color @author = author @fields = fields || [] @footer = footer @image = image && (image.is_a?(String) ? Image.new(image) : image) @thumbnail = thumbnail && (thumbnail.is_a?(String) ? Thumbnail.new(thumbnail) : thumbnail) @type = "rich" else @title = data[:title] @description = data[:description] @url = data[:url] @timestamp = data[:timestamp] && Time.iso8601(data[:timestamp]) @type = data[:type] @color = data[:color] && Color.new(data[:color]) @footer = data[:footer] && Footer.new(data[:footer][:text], icon: data[:footer][:icon_url]) @author = if data[:author] Author.new(data[:author][:name], icon: data[:author][:icon_url], url: data[:author][:url]) end @thumbnail = data[:thumbnail] && Thumbnail.new(data[:thumbnail]) @image = data[:image] && Image.new(data[:image]) @video = data[:video] && Video.new(data[:video]) @provider = data[:provider] && Provider.new(data[:provider]) @fields = data[:fields] ? data[:fields].map { |f| Field.new(f[:name], f[:value], inline: f[:inline]) } : [] end end
Public Instance Methods
# File lib/discorb/embed.rb, line 81 def image=(value) @image = (value.is_a?(String)) ? Image.new(value) : value end
# File lib/discorb/embed.rb, line 85 def thumbnail=(value) @thumbnail = (value.is_a?(String)) ? Thumbnail.new(value) : value end
Convert embed to hash.
@see discord.com/developers/docs/resources/channel#embed-object-embed-structure Offical Discord API Docs @return [Hash] Converted embed.
# File lib/discorb/embed.rb, line 95 def to_hash { title: @title, description: @description, url: @url, timestamp: @timestamp&.iso8601, color: @color&.to_i, footer: @footer&.to_hash, image: @image&.to_hash, thumbnail: @thumbnail&.to_hash, author: @author&.to_hash, fields: @fields&.map { |f| f.to_hash }, } end