Class: Rubycord::Attachment

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

Overview

An attachment to a message

Constant Summary

Constants included from AttachmentAttributes

Rubycord::AttachmentAttributes::FLAGS

Instance Attribute Summary collapse

Attributes included from AttachmentAttributes

#flags

Attributes included from IDObject

#id

Instance Method Summary collapse

Methods included from AttachmentAttributes

#remix?, #spoiler?

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.



44
45
46
# File 'lib/rubycord/data/attachment.rb', line 44

def content_type
  @content_type
end

#descriptionString? (readonly)

Returns the attachment's description.

Returns:

  • (String, nil)

    the attachment's description.



41
42
43
# File 'lib/rubycord/data/attachment.rb', line 41

def description
  @description
end

#duration_secsFloat? (readonly)

Returns the duration of the audio file (currently for voice messages).

Returns:

  • (Float, nil)

    the duration of the audio file (currently for voice messages).



63
64
65
# File 'lib/rubycord/data/attachment.rb', line 63

def duration_secs
  @duration_secs
end

#filenameString (readonly)

Returns the attachment's filename.

Returns:

  • (String)

    the attachment's filename.



35
36
37
# File 'lib/rubycord/data/attachment.rb', line 35

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.



57
58
59
# File 'lib/rubycord/data/attachment.rb', line 57

def height
  @height
end

#messageMessage (readonly)

Returns the message this attachment belongs to.

Returns:

  • (Message)

    the message this attachment belongs to.



32
33
34
# File 'lib/rubycord/data/attachment.rb', line 32

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.



54
55
56
# File 'lib/rubycord/data/attachment.rb', line 54

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.



47
48
49
# File 'lib/rubycord/data/attachment.rb', line 47

def size
  @size
end

#titleString? (readonly)

Returns the attachment's title.

Returns:

  • (String, nil)

    the attachment's title.



38
39
40
# File 'lib/rubycord/data/attachment.rb', line 38

def title
  @title
end

#urlString (readonly)

Returns the CDN URL this attachment can be downloaded at.

Returns:

  • (String)

    the CDN URL this attachment can be downloaded at.



50
51
52
# File 'lib/rubycord/data/attachment.rb', line 50

def url
  @url
end

#waveformString? (readonly)

Returns base64 encoded bytearray representing a sampled waveform (currently for voice messages).

Returns:

  • (String, nil)

    base64 encoded bytearray representing a sampled waveform (currently for voice messages).



66
67
68
# File 'lib/rubycord/data/attachment.rb', line 66

def waveform
  @waveform
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.



60
61
62
# File 'lib/rubycord/data/attachment.rb', line 60

def width
  @width
end

Instance Method Details

#audio?true, false

Returns whether this file is an audio file.

Returns:

  • (true, false)

    whether this file is an audio file.



100
101
102
# File 'lib/rubycord/data/attachment.rb', line 100

def audio?
  !@duration_secs.nil?
end

#ephemeral?true, false

Returns whether this attachment is ephemeral.

Returns:

  • (true, false)

    whether this attachment is ephemeral.



105
106
107
# File 'lib/rubycord/data/attachment.rb', line 105

def ephemeral?
  @ephemeral
end

#image?true, false

Returns whether this file is an image file.

Returns:

  • (true, false)

    whether this file is an image file.



95
96
97
# File 'lib/rubycord/data/attachment.rb', line 95

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