Class: Discord::Embed
- Inherits:
-
Object
- Object
- Discord::Embed
- Defined in:
- lib/discord_notifier/embed.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #add_field(params) ⇒ Object (also: #field)
- #author(params) ⇒ Object
- #color(val) ⇒ Object
- #description(str) ⇒ Object
- #footer(params) ⇒ Object
- #image(params) ⇒ Object
-
#initialize(&block) ⇒ Embed
constructor
A new instance of Embed.
- #provider(params) ⇒ Object
- #thumbnail(params) ⇒ Object
- #timestamp(date) ⇒ Object
- #title(str) ⇒ Object
- #url(str) ⇒ Object
- #video(params) ⇒ Object
Constructor Details
#initialize(&block) ⇒ Embed
Returns a new instance of Embed.
5 6 7 8 |
# File 'lib/discord_notifier/embed.rb', line 5 def initialize(&block) @data = {} self.instance_exec(&block) if block_given? end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
3 4 5 |
# File 'lib/discord_notifier/embed.rb', line 3 def data @data end |
Instance Method Details
#add_field(params) ⇒ Object Also known as: field
78 79 80 81 82 83 |
# File 'lib/discord_notifier/embed.rb', line 78 def add_field(params) raise ArgumentError, "Field Embed data must be a Hash" unless params.is_a?(Hash) @data[:fields] ||= [] @data[:fields] << params end |
#author(params) ⇒ Object
66 67 68 69 70 |
# File 'lib/discord_notifier/embed.rb', line 66 def (params) raise ArgumentError, "Author Embed data must be a Hash" unless params.is_a?(Hash) @data[:author] = params end |
#color(val) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/discord_notifier/embed.rb', line 30 def color(val) case val when String @data[:color] = val.delete('#').to_i(16) when Integer raise ArgumentError, 'Color must be 24 bit' if val >= 16_777_216 @data[:color] = val else raise ArgumentError, 'Color must be hex or 24 bit int' end end |
#description(str) ⇒ Object
15 16 17 18 |
# File 'lib/discord_notifier/embed.rb', line 15 def description(str) raise ArgumentError, 'Description Embed data must be a String' unless str.is_a?(String) @data[:description] = str end |
#footer(params) ⇒ Object
72 73 74 75 76 |
# File 'lib/discord_notifier/embed.rb', line 72 def (params) raise ArgumentError, "Footer Embed data must be a Hash" unless params.is_a?(Hash) @data[:footer] = params end |
#image(params) ⇒ Object
54 55 56 57 58 |
# File 'lib/discord_notifier/embed.rb', line 54 def image(params) raise ArgumentError, "Image Embed data must be a Hash" unless params.is_a?(Hash) @data[:image] = params end |
#provider(params) ⇒ Object
60 61 62 63 64 |
# File 'lib/discord_notifier/embed.rb', line 60 def provider(params) raise ArgumentError, "Provider Embed data must be a Hash" unless params.is_a?(Hash) @data[:provider] = params end |
#thumbnail(params) ⇒ Object
42 43 44 45 46 |
# File 'lib/discord_notifier/embed.rb', line 42 def thumbnail(params) raise ArgumentError, "Thumbnail Embed data must be a Hash" unless params.is_a?(Hash) @data[:thumbnail] = params end |
#timestamp(date) ⇒ Object
25 26 27 28 |
# File 'lib/discord_notifier/embed.rb', line 25 def (date) raise ArgumentError, 'Timestamp Embed data must be a Date' unless date.is_a?(DateTime) @data[:timestamp] = date end |
#title(str) ⇒ Object
10 11 12 13 |
# File 'lib/discord_notifier/embed.rb', line 10 def title(str) raise ArgumentError, 'Title Embed data must be a String' unless str.is_a?(String) @data[:title] = str end |
#url(str) ⇒ Object
20 21 22 23 |
# File 'lib/discord_notifier/embed.rb', line 20 def url(str) raise ArgumentError, 'URL Embed data must be a String' unless str.is_a?(String) @data[:url] = str end |
#video(params) ⇒ Object
48 49 50 51 52 |
# File 'lib/discord_notifier/embed.rb', line 48 def video(params) raise ArgumentError, "Video Embed data must be a Hash" unless params.is_a?(Hash) @data[:video] = params end |