class MijDiscord::Data::Embed
Attributes
color[R]
description[R]
fields[R]
image[R]
provider[R]
thumbnail[R]
timestamp[R]
title[R]
type[R]
url[R]
video[R]
Public Class Methods
construct(data)
click to toggle source
# File lib/mij-discord/data/embed.rb, line 79 def self.construct(data) embed = { 'type' => data.try_keys(:type, 'type') || :rich, 'title' => data.try_keys(:title, 'title'), 'description' => data.try_keys(:description, 'description'), 'url' => data.try_keys(:url, 'url'), 'color' => data.try_keys(:color, 'color')&.to_i, 'timestamp' => data.try_keys(:timestamp, 'timestamp')&.iso8601, 'footer' => data.try_keys(:footer, 'footer')&.to_hash, 'thumbnail' => data.try_keys(:thumbnail, 'thumbnail')&.to_hash, 'image' => data.try_keys(:image, 'image')&.to_hash, 'video' => data.try_keys(:video, 'video')&.to_hash, 'author' => data.try_keys(:author, 'author')&.to_hash, 'provider' => data.try_keys(:provider, 'provider')&.to_hash, 'fields' => data.try_keys(:fields, 'fields')&.map(&:to_hash), }.delete_if {|_,v| v.nil? } embed end
new(data)
click to toggle source
# File lib/mij-discord/data/embed.rb, line 31 def initialize(data) @type, @url = data['type'], data['url'] @title, @description = data['title'], data['description'] @color = ColorRGB.new(data['color']) if data['color'] @timestamp = Time.parse(data['timestamp']).utc if data['timestamp'] @footer = EmbedFooter.new(data['footer']) if data['footer'] @thumbnail = EmbedMedia.new(data['thumbnail']) if data['thumbnail'] @image = EmbedMedia.new(data['image']) if data['image'] @video = EmbedMedia.new(data['video']) if data['video'] @author = EmbedAuthor.new(data['author']) if data['author'] @provider = EmbedProvider.new(data['provider']) if data['provider'] @fields = data['fields']&.map {|x| EmbedField.new(x) } end
Public Instance Methods
inspect()
click to toggle source
# File lib/mij-discord/data/embed.rb, line 50 def inspect MijDiscord.make_inspect(self, :type, :title, :description, :url, :color, :timestamp, :image, :video, :thumbnail, :footer, :author, :provider, :fields) end
to_hash()
click to toggle source
# File lib/mij-discord/data/embed.rb, line 56 def to_hash self.class.construct({ type: @type, title: @title, description: @description, url: @url, color: @color, timestamp: @timestamp, footer: @footer, thumbnail: @thumbnail, image: @image, video: @video, author: @author, provider: @provider, fields: @fields, }) end