Class: DiscordRDA::Embed

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

Overview

Represents a Discord message embed.

Defined Under Namespace

Classes: Builder

Constant Summary collapse

TYPES =

Embed types

%w[rich image video gifv article link].freeze

Instance Attribute Summary

Attributes inherited from Entity

#id

Instance Method Summary collapse

Methods inherited from Entity

#==, attribute, #created_at, from_hash, #hash, #initialize, #inspect, #to_h, #to_json

Constructor Details

This class inherits a constructor from DiscordRDA::Entity

Instance Method Details

#color_objectColor

Get color as Color object

Returns:

  • (Color)

    Embed color



26
27
28
# File 'lib/discord_rda/entity/embed.rb', line 26

def color_object
  Color.new(color)
end

#embed_authorEmbedAuthor?

Get author

Returns:



74
75
76
# File 'lib/discord_rda/entity/embed.rb', line 74

def embed_author
  EmbedAuthor.new(@raw_data['author']) if @raw_data['author']
end

#embed_fieldsArray<EmbedField>

Get fields

Returns:



38
39
40
# File 'lib/discord_rda/entity/embed.rb', line 38

def embed_fields
  (@raw_data['fields'] || []).map { |f| EmbedField.new(f) }
end

Get footer

Returns:



44
45
46
# File 'lib/discord_rda/entity/embed.rb', line 44

def embed_footer
  EmbedFooter.new(@raw_data['footer']) if @raw_data['footer']
end

#embed_imageEmbedImage?

Get image

Returns:



50
51
52
# File 'lib/discord_rda/entity/embed.rb', line 50

def embed_image
  EmbedImage.new(@raw_data['image']) if @raw_data['image']
end

#embed_providerEmbedProvider?

Get provider

Returns:



68
69
70
# File 'lib/discord_rda/entity/embed.rb', line 68

def embed_provider
  EmbedProvider.new(@raw_data['provider']) if @raw_data['provider']
end

#embed_thumbnailEmbedThumbnail?

Get thumbnail

Returns:



56
57
58
# File 'lib/discord_rda/entity/embed.rb', line 56

def embed_thumbnail
  EmbedThumbnail.new(@raw_data['thumbnail']) if @raw_data['thumbnail']
end

#embed_videoEmbedVideo?

Get video

Returns:



62
63
64
# File 'lib/discord_rda/entity/embed.rb', line 62

def embed_video
  EmbedVideo.new(@raw_data['video']) if @raw_data['video']
end

#empty?Boolean

Check if embed is empty

Returns:

  • (Boolean)

    True if empty



86
87
88
# File 'lib/discord_rda/entity/embed.rb', line 86

def empty?
  title.nil? && description.nil? && !has_fields?
end

#has_fields?Boolean

Check if embed has fields

Returns:

  • (Boolean)

    True if has fields



32
33
34
# File 'lib/discord_rda/entity/embed.rb', line 32

def has_fields?
  fields.any?
end

#has_media?Boolean

Check if embed has image or thumbnail

Returns:

  • (Boolean)

    True if has media



80
81
82
# File 'lib/discord_rda/entity/embed.rb', line 80

def has_media?
  @raw_data['image'] || @raw_data['thumbnail']
end