Class: RubyCord::User::Avatar

Inherits:
Object
  • Object
show all
Defined in:
lib/rubycord/user/avatar.rb

Overview

Represents a single asset.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#animated?Boolean (readonly)

return [Boolean]

Returns:

  • (Boolean)


# File 'lib/rubycord/user/avatar.rb', line 11


#hashString? (readonly)

Returns The hash of asset.

Returns:

  • (String, nil)

    The hash of asset.



9
10
11
# File 'lib/rubycord/user/avatar.rb', line 9

def hash
  @hash
end

Instance Method Details

#default?Boolean

Returns If this user has a default avatar.

Returns:

  • (Boolean)

    If this user has a default avatar.



29
30
31
# File 'lib/rubycord/user/avatar.rb', line 29

def default?
  @hash.nil?
end

#inspectString

Returns Object class and attributes.

Returns:

  • (String)

    Object class and attributes.



57
58
59
# File 'lib/rubycord/user/avatar.rb', line 57

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.



48
49
50
51
52
53
54
# File 'lib/rubycord/user/avatar.rb', line 48

def url(image_format: nil, size: 1024)
  if default?
    "https://cdn.discordapp.com/embed/avatars/#{@discriminator.to_i % 5}.png"
  else
    "https://cdn.discordapp.com/avatars/#{@id}/#{@hash}.#{image_format or (animated? ? "gif" : "webp")}?size=#{size}"
  end
end