Class: DiscordRDA::EmbedBuilder
- Inherits:
-
Object
- Object
- DiscordRDA::EmbedBuilder
- Defined in:
- lib/discord_rda/entity/message_builder.rb
Overview
Builder for embed details
Instance Method Summary collapse
-
#author(name:, url: nil, icon_url: nil) ⇒ Object
Set embed author.
-
#color(value) ⇒ Object
Set embed color.
-
#description(text) ⇒ Object
Set embed description.
-
#field(name:, value:, inline: false) ⇒ Object
Add a field to the embed.
-
#footer(text:, icon_url: nil) ⇒ Object
Set embed footer.
-
#image(url) ⇒ Object
Set embed image.
-
#initialize(base = {}) ⇒ EmbedBuilder
constructor
A new instance of EmbedBuilder.
-
#thumbnail(url) ⇒ Object
Set embed thumbnail.
-
#timestamp(time) ⇒ Object
Set embed timestamp.
-
#title(text) ⇒ Object
Set embed title.
-
#to_h ⇒ Object
Convert to hash.
-
#url(link) ⇒ Object
Set embed URL.
Constructor Details
#initialize(base = {}) ⇒ EmbedBuilder
Returns a new instance of EmbedBuilder.
114 115 116 |
# File 'lib/discord_rda/entity/message_builder.rb', line 114 def initialize(base = {}) @embed = base end |
Instance Method Details
#author(name:, url: nil, icon_url: nil) ⇒ Object
Set embed author
175 176 177 178 179 180 |
# File 'lib/discord_rda/entity/message_builder.rb', line 175 def (name:, url: nil, icon_url: nil) @embed[:author] = { name: name } @embed[:author][:url] = url if url @embed[:author][:icon_url] = icon_url if icon_url self end |
#color(value) ⇒ Object
Set embed color
131 132 133 134 |
# File 'lib/discord_rda/entity/message_builder.rb', line 131 def color(value) @embed[:color] = value.is_a?(Color) ? value.to_i : value self end |
#description(text) ⇒ Object
Set embed description
125 126 127 128 |
# File 'lib/discord_rda/entity/message_builder.rb', line 125 def description(text) @embed[:description] = text self end |
#field(name:, value:, inline: false) ⇒ Object
Add a field to the embed
149 150 151 152 153 |
# File 'lib/discord_rda/entity/message_builder.rb', line 149 def field(name:, value:, inline: false) @embed[:fields] ||= [] @embed[:fields] << { name: name, value: value, inline: inline } self end |
#footer(text:, icon_url: nil) ⇒ Object
Set embed footer
156 157 158 159 160 |
# File 'lib/discord_rda/entity/message_builder.rb', line 156 def (text:, icon_url: nil) @embed[:footer] = { text: text } @embed[:footer][:icon_url] = icon_url if icon_url self end |
#image(url) ⇒ Object
Set embed image
163 164 165 166 |
# File 'lib/discord_rda/entity/message_builder.rb', line 163 def image(url) @embed[:image] = { url: url } self end |
#thumbnail(url) ⇒ Object
Set embed thumbnail
169 170 171 172 |
# File 'lib/discord_rda/entity/message_builder.rb', line 169 def thumbnail(url) @embed[:thumbnail] = { url: url } self end |
#timestamp(time) ⇒ Object
Set embed timestamp
143 144 145 146 |
# File 'lib/discord_rda/entity/message_builder.rb', line 143 def (time) @embed[:timestamp] = time.iso8601 self end |
#title(text) ⇒ Object
Set embed title
119 120 121 122 |
# File 'lib/discord_rda/entity/message_builder.rb', line 119 def title(text) @embed[:title] = text self end |
#to_h ⇒ Object
Convert to hash
183 184 185 |
# File 'lib/discord_rda/entity/message_builder.rb', line 183 def to_h @embed end |
#url(link) ⇒ Object
Set embed URL
137 138 139 140 |
# File 'lib/discord_rda/entity/message_builder.rb', line 137 def url(link) @embed[:url] = link self end |