Class: Discorb::Embed
- Inherits:
-
Object
- Object
- Discorb::Embed
- Defined in:
- lib/discorb/embed.rb
Overview
Represents an embed of discord.
Defined Under Namespace
Classes: Author, Field, Footer, Image, Provider, Thumbnail, Video
Instance Attribute Summary collapse
-
#author -> Discorb::Embed::Author?
The author of embed.
-
#color -> Discorb::Color?
The color of embed.
-
#description -> String?
The description of embed.
-
#fields -> Array<Discorb::Embed::Field>
The fields of embed.
-
#footer -> Discorb::Embed::Footer?
The footer of embed.
-
#image -> Discorb::Embed::Image
The image of embed.
-
#thumbnail -> Discorb::Embed::Thumbnail
The thumbnail of embed.
-
#timestamp -> Time?
The timestamp of embed.
-
#title -> String?
The title of embed.
-
#type -> Symbol
readonly
The type of embed.
-
#url -> String?
The url of embed.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(title = nil, description = nil, color: nil, url: nil, timestamp: nil, author: nil, fields: nil, footer: nil, image: nil, thumbnail: nil) -> Embed
constructor
Initialize a new Embed object.
- #inspect -> Object
-
#to_hash -> Hash
Convert embed to hash.
Constructor Details
#initialize(title = nil, description = nil, color: nil, url: nil, timestamp: nil, author: nil, fields: nil, footer: nil, image: nil, thumbnail: nil) -> Embed
Initialize a new Embed object.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# 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 ) @title = title @description = description @url = url @timestamp = @color = color && (color.is_a?(Color) ? color : Color.new(color)) @author = @fields = fields || [] @footer = @image = image && (image.is_a?(String) ? Image.new(image) : image) @thumbnail = thumbnail && (thumbnail.is_a?(String) ? Thumbnail.new(thumbnail) : thumbnail) @type = :rich end |
Instance Attribute Details
#author -> Discorb::Embed::Author?
Returns The author of embed.
19 20 21 |
# File 'lib/discorb/embed.rb', line 19 def @author end |
#color -> Discorb::Color?
Returns The color of embed.
17 18 19 |
# File 'lib/discorb/embed.rb', line 17 def color @color end |
#description -> String?
Returns The description of embed.
11 12 13 |
# File 'lib/discorb/embed.rb', line 11 def description @description end |
#fields -> Array<Discorb::Embed::Field>
Returns The fields of embed.
21 22 23 |
# File 'lib/discorb/embed.rb', line 21 def fields @fields end |
#footer -> Discorb::Embed::Footer?
Returns The footer of embed.
23 24 25 |
# File 'lib/discorb/embed.rb', line 23 def @footer end |
#image -> Discorb::Embed::Image
Returns The image of embed.
28 29 30 |
# File 'lib/discorb/embed.rb', line 28 def image @image end |
#thumbnail -> Discorb::Embed::Thumbnail
Returns The thumbnail of embed.
28 29 30 |
# File 'lib/discorb/embed.rb', line 28 def thumbnail @thumbnail end |
#timestamp -> Time?
Returns The timestamp of embed.
15 16 17 |
# File 'lib/discorb/embed.rb', line 15 def @timestamp end |
#title -> String?
Returns The title of embed.
9 10 11 |
# File 'lib/discorb/embed.rb', line 9 def title @title end |
#type -> Symbol (readonly)
Returns The type of embed.
25 26 27 |
# File 'lib/discorb/embed.rb', line 25 def type @type end |
#url -> String?
Returns The url of embed.
13 14 15 |
# File 'lib/discorb/embed.rb', line 13 def url @url end |
Class Method Details
.from_hash(data) -> Object
131 132 133 134 135 |
# File 'lib/discorb/embed.rb', line 131 def self.from_hash(data) inst = allocate inst.initialize_hash(data) inst end |
Instance Method Details
#inspect -> Object
105 106 107 |
# File 'lib/discorb/embed.rb', line 105 def inspect "#<#{self.class} \"#{@title}\">" end |
#to_hash -> Hash
Convert embed to hash.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/discorb/embed.rb', line 115 def to_hash # @type var ret: Hash[untyped, untyped] ret = { type: "rich" } ret[:title] = @title if @title ret[:description] = @description if @description ret[:url] = @url if @url ret[:timestamp] = @timestamp&.iso8601 if @timestamp ret[:color] = @color&.to_i if @color ret[:footer] = @footer&.to_hash if @footer ret[:image] = @image&.to_hash if @image ret[:thumbnail] = @thumbnail&.to_hash if @thumbnail ret[:author] = @author&.to_hash if @author ret[:fields] = @fields&.map(&:to_hash) if @fields.any? ret end |