Class: Discordrb::Attachment

Inherits:
Object
  • Object
show all
Includes:
IDObject
Defined in:
lib/discordrb/data/attachment.rb

Overview

An attachment to a message

Instance Attribute Summary collapse

Attributes included from IDObject

#id

Instance Method Summary collapse

Methods included from IDObject

#==, #creation_time, synthesise

Instance Attribute Details

#content_typeString? (readonly)

Returns the attachment’s media type.

Returns:

  • (String, nil)

    the attachment’s media type.



34
35
36
# File 'lib/discordrb/data/attachment.rb', line 34

def content_type
  @content_type
end

#descriptionString? (readonly)

Returns the attachment’s description.

Returns:

  • (String, nil)

    the attachment’s description.



31
32
33
# File 'lib/discordrb/data/attachment.rb', line 31

def description
  @description
end

#ephemeraltrue, false (readonly) Also known as: ephemeral?

Returns whether this attachment is ephemeral.

Returns:

  • (true, false)

    whether this attachment is ephemeral.



37
38
39
# File 'lib/discordrb/data/attachment.rb', line 37

def ephemeral
  @ephemeral
end

#filenameString (readonly)

Returns the attachment’s filename.

Returns:

  • (String)

    the attachment’s filename.



19
20
21
# File 'lib/discordrb/data/attachment.rb', line 19

def filename
  @filename
end

#heightInteger? (readonly)

Returns the height of an image file, in pixels, or nil if the file is not an image.

Returns:

  • (Integer, nil)

    the height of an image file, in pixels, or nil if the file is not an image.



28
29
30
# File 'lib/discordrb/data/attachment.rb', line 28

def height
  @height
end

#messageMessage (readonly)

Returns the message this attachment belongs to.

Returns:

  • (Message)

    the message this attachment belongs to.



9
10
11
# File 'lib/discordrb/data/attachment.rb', line 9

def message
  @message
end

#proxy_urlString (readonly)

Returns the attachment’s proxy URL - I’m not sure what exactly this does, but I think it has something to do with CDNs.

Returns:

  • (String)

    the attachment’s proxy URL - I’m not sure what exactly this does, but I think it has something to do with CDNs.



16
17
18
# File 'lib/discordrb/data/attachment.rb', line 16

def proxy_url
  @proxy_url
end

#sizeInteger (readonly)

Returns the attachment’s file size in bytes.

Returns:

  • (Integer)

    the attachment’s file size in bytes.



22
23
24
# File 'lib/discordrb/data/attachment.rb', line 22

def size
  @size
end

#urlString (readonly)

Returns the CDN URL this attachment can be downloaded at.

Returns:

  • (String)

    the CDN URL this attachment can be downloaded at.



12
13
14
# File 'lib/discordrb/data/attachment.rb', line 12

def url
  @url
end

#widthInteger? (readonly)

Returns the width of an image file, in pixels, or nil if the file is not an image.

Returns:

  • (Integer, nil)

    the width of an image file, in pixels, or nil if the file is not an image.



25
26
27
# File 'lib/discordrb/data/attachment.rb', line 25

def width
  @width
end

Instance Method Details

#image?true, false

Returns whether this file is an image file.

Returns:

  • (true, false)

    whether this file is an image file.



62
63
64
# File 'lib/discordrb/data/attachment.rb', line 62

def image?
  !(@width.nil? || @height.nil?)
end

#spoiler?true, false

Returns whether this file is tagged as a spoiler.

Returns:

  • (true, false)

    whether this file is tagged as a spoiler.



67
68
69
# File 'lib/discordrb/data/attachment.rb', line 67

def spoiler?
  @filename.start_with? 'SPOILER_'
end