Class: Discorb::Asset

Inherits:
DiscordModel show all
Defined in:
lib/discorb/asset.rb

Overview

Represents a single asset.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from DiscordModel

#==, #eql?

Instance Attribute Details

#animated? -> Boolean (readonly)

Returns Whether the asset is animated.

Returns:

  • (Boolean)

    Whether the asset is animated.



# File 'lib/discorb/asset.rb', line 11

#hash -> String (readonly)

Returns The hash of asset.

Returns:

  • (String)

    The hash of asset.



9
10
11
# File 'lib/discorb/asset.rb', line 9

def hash
  @hash
end

Instance Method Details

#inspect -> Object



44
45
46
# File 'lib/discorb/asset.rb', line 44

def inspect
  "#<#{self.class} #{@target.class} #{@hash}>"
end

#url(image_format: nil, size: 1024) -> String

URL of the asset.

Parameters:

  • image_format (String) (defaults to: nil)

    The image format.

  • size (Integer) (defaults to: 1024)

    The size of the image.

Returns:

  • (String)

    URL of the asset.



39
40
41
42
# File 'lib/discorb/asset.rb', line 39

def url(image_format: nil, size: 1024)
  path = @path || "#{endpoint}/#{@target.id}"
  "https://cdn.discordapp.com/#{path}/#{@hash}.#{image_format or (animated? ? "gif" : "webp")}?size=#{size}"
end