Class: Rubycord::Webhooks::Embed
- Inherits:
-
Object
- Object
- Rubycord::Webhooks::Embed
- Defined in:
- lib/rubycord/webhooks/embeds.rb
Overview
An embed is a multipart-style attachment to a webhook message that can have a variety of different purposes and appearances.
Instance Attribute Summary collapse
-
#author ⇒ EmbedAuthor?
Author for this embed.
-
#colour ⇒ Integer?
(also: #color)
The colour of the bar to the side, in decimal form.
-
#description ⇒ String?
Description for this embed.
-
#fields ⇒ Array<EmbedField>
The fields attached to this embed.
-
#footer ⇒ EmbedFooter?
Footer for this embed.
-
#image ⇒ EmbedImage?
Image for this embed.
-
#thumbnail ⇒ EmbedThumbnail?
Thumbnail for this embed.
-
#timestamp ⇒ Time?
Timestamp for this embed.
-
#title ⇒ String?
Title of the embed that will be displayed above everything else.
-
#url ⇒ String?
URL the title should point to.
Instance Method Summary collapse
-
#<<(field) ⇒ Object
Add a field object to this embed.
-
#add_field(name: nil, value: nil, inline: nil) ⇒ Object
Convenience method to add a field to the embed without having to create one manually.
-
#initialize(title: nil, description: nil, url: nil, timestamp: nil, colour: nil, color: nil, footer: nil, image: nil, thumbnail: nil, video: nil, provider: nil, author: nil, fields: []) ⇒ Embed
constructor
A new instance of Embed.
-
#to_hash ⇒ Hash
A hash representation of this embed, to be converted to JSON.
Constructor Details
#initialize(title: nil, description: nil, url: nil, timestamp: nil, colour: nil, color: nil, footer: nil, image: nil, thumbnail: nil, video: nil, provider: nil, author: nil, fields: []) ⇒ Embed
Returns a new instance of Embed.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/rubycord/webhooks/embeds.rb', line 5 def initialize(title: nil, description: nil, url: nil, timestamp: nil, colour: nil, color: nil, footer: nil, image: nil, thumbnail: nil, video: nil, provider: nil, author: nil, fields: []) @title = title @description = description @url = url @timestamp = self.colour = colour || color @footer = @image = image @thumbnail = thumbnail @video = video @provider = provider @author = @fields = fields end |
Instance Attribute Details
#author ⇒ EmbedAuthor?
Returns author for this embed.
81 82 83 |
# File 'lib/rubycord/webhooks/embeds.rb', line 81 def @author end |
#colour ⇒ Integer? Also known as: color
Returns the colour of the bar to the side, in decimal form.
34 35 36 |
# File 'lib/rubycord/webhooks/embeds.rb', line 34 def colour @colour end |
#description ⇒ String?
Returns description for this embed.
25 26 27 |
# File 'lib/rubycord/webhooks/embeds.rb', line 25 def description @description end |
#fields ⇒ Array<EmbedField>
Returns the fields attached to this embed.
101 102 103 |
# File 'lib/rubycord/webhooks/embeds.rb', line 101 def fields @fields end |
#footer ⇒ EmbedFooter?
Returns footer for this embed.
63 64 65 |
# File 'lib/rubycord/webhooks/embeds.rb', line 63 def @footer end |
#image ⇒ EmbedImage?
Returns image for this embed.
69 70 71 |
# File 'lib/rubycord/webhooks/embeds.rb', line 69 def image @image end |
#thumbnail ⇒ EmbedThumbnail?
Returns thumbnail for this embed.
75 76 77 |
# File 'lib/rubycord/webhooks/embeds.rb', line 75 def thumbnail @thumbnail end |
#timestamp ⇒ Time?
Returns timestamp for this embed. Will be displayed just below the title.
31 32 33 |
# File 'lib/rubycord/webhooks/embeds.rb', line 31 def @timestamp end |
#title ⇒ String?
Returns title of the embed that will be displayed above everything else.
22 23 24 |
# File 'lib/rubycord/webhooks/embeds.rb', line 22 def title @title end |
#url ⇒ String?
Returns URL the title should point to.
28 29 30 |
# File 'lib/rubycord/webhooks/embeds.rb', line 28 def url @url end |
Instance Method Details
#<<(field) ⇒ Object
Add a field object to this embed.
85 86 87 |
# File 'lib/rubycord/webhooks/embeds.rb', line 85 def <<(field) @fields << field end |
#add_field(name: nil, value: nil, inline: nil) ⇒ Object
Convenience method to add a field to the embed without having to create one manually.
96 97 98 |
# File 'lib/rubycord/webhooks/embeds.rb', line 96 def add_field(name: nil, value: nil, inline: nil) self << EmbedField.new(name: name, value: value, inline: inline) end |
#to_hash ⇒ Hash
Returns a hash representation of this embed, to be converted to JSON.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/rubycord/webhooks/embeds.rb', line 104 def to_hash { title: @title, description: @description, url: @url, timestamp: @timestamp&.utc&.iso8601, color: @colour, footer: @footer&.to_hash, image: @image&.to_hash, thumbnail: @thumbnail&.to_hash, video: @video&.to_hash, provider: @provider&.to_hash, author: @author&.to_hash, fields: @fields.map(&:to_hash) } end |