Class: DiscordRDA::Embed::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/discord_rda/entity/embed.rb

Overview

Builder class for creating embeds

Instance Method Summary collapse

Constructor Details

#initializeBuilder

Returns a new instance of Builder.



92
93
94
# File 'lib/discord_rda/entity/embed.rb', line 92

def initialize
  @data = {}
end

Instance Method Details

#author(name:, url: nil, icon_url: nil) ⇒ Object



149
150
151
152
153
154
# File 'lib/discord_rda/entity/embed.rb', line 149

def author(name:, url: nil, icon_url: nil)
  @data['author'] = { 'name' => name }
  @data['author']['url'] = url if url
  @data['author']['icon_url'] = icon_url if icon_url
  self
end

#buildObject



156
157
158
# File 'lib/discord_rda/entity/embed.rb', line 156

def build
  Embed.new(@data)
end

#color(value) ⇒ Object



116
117
118
119
# File 'lib/discord_rda/entity/embed.rb', line 116

def color(value)
  @data['color'] = value.is_a?(Color) ? value.to_i : value
  self
end

#description(value) ⇒ Object



101
102
103
104
# File 'lib/discord_rda/entity/embed.rb', line 101

def description(value)
  @data['description'] = value
  self
end

#field(name:, value:, inline: false) ⇒ Object



121
122
123
124
125
# File 'lib/discord_rda/entity/embed.rb', line 121

def field(name:, value:, inline: false)
  @data['fields'] ||= []
  @data['fields'] << { 'name' => name, 'value' => value, 'inline' => inline }
  self
end


127
128
129
130
131
# File 'lib/discord_rda/entity/embed.rb', line 127

def footer(text:, icon_url: nil)
  @data['footer'] = { 'text' => text }
  @data['footer']['icon_url'] = icon_url if icon_url
  self
end

#image(url:, proxy_url: nil, height: nil, width: nil) ⇒ Object



133
134
135
136
137
138
139
# File 'lib/discord_rda/entity/embed.rb', line 133

def image(url:, proxy_url: nil, height: nil, width: nil)
  @data['image'] = { 'url' => url }
  @data['image']['proxy_url'] = proxy_url if proxy_url
  @data['image']['height'] = height if height
  @data['image']['width'] = width if width
  self
end

#thumbnail(url:, proxy_url: nil, height: nil, width: nil) ⇒ Object



141
142
143
144
145
146
147
# File 'lib/discord_rda/entity/embed.rb', line 141

def thumbnail(url:, proxy_url: nil, height: nil, width: nil)
  @data['thumbnail'] = { 'url' => url }
  @data['thumbnail']['proxy_url'] = proxy_url if proxy_url
  @data['thumbnail']['height'] = height if height
  @data['thumbnail']['width'] = width if width
  self
end

#timestamp(value) ⇒ Object



111
112
113
114
# File 'lib/discord_rda/entity/embed.rb', line 111

def timestamp(value)
  @data['timestamp'] = value.iso8601
  self
end

#title(value) ⇒ Object



96
97
98
99
# File 'lib/discord_rda/entity/embed.rb', line 96

def title(value)
  @data['title'] = value
  self
end

#to_hObject



160
161
162
# File 'lib/discord_rda/entity/embed.rb', line 160

def to_h
  @data
end

#url(value) ⇒ Object



106
107
108
109
# File 'lib/discord_rda/entity/embed.rb', line 106

def url(value)
  @data['url'] = value
  self
end