Class: DiscordRDA::Attachment
- Defined in:
- lib/discord_rda/entity/attachment.rb
Overview
Represents a Discord message attachment.
Instance Attribute Summary
Attributes inherited from Entity
Instance Method Summary collapse
-
#audio? ⇒ Boolean
Check if attachment is audio.
-
#dimensions ⇒ Array<Integer>?
Get dimensions as [width, height].
-
#duration_formatted ⇒ String?
Get duration formatted (for voice messages).
-
#ephemeral? ⇒ Boolean
Check if attachment is ephemeral (will be deleted).
-
#has_dimensions? ⇒ Boolean
Check if attachment has dimensions (image/video).
-
#image? ⇒ Boolean
Check if attachment is an image.
-
#size_human ⇒ String
Get file size in human readable format.
-
#text? ⇒ Boolean
Check if attachment is a text file.
-
#video? ⇒ Boolean
Check if attachment is a video.
-
#voice_message? ⇒ Boolean
Check if this is a voice message.
Methods inherited from Entity
#==, attribute, #created_at, from_hash, #hash, #initialize, #inspect, #to_h, #to_json
Constructor Details
This class inherits a constructor from DiscordRDA::Entity
Instance Method Details
#audio? ⇒ Boolean
Check if attachment is audio
34 35 36 |
# File 'lib/discord_rda/entity/attachment.rb', line 34 def audio? content_type&.start_with?('audio/') end |
#dimensions ⇒ Array<Integer>?
Get dimensions as [width, height]
52 53 54 |
# File 'lib/discord_rda/entity/attachment.rb', line 52 def dimensions [width, height] if has_dimensions? end |
#duration_formatted ⇒ String?
Get duration formatted (for voice messages)
74 75 76 77 78 79 80 |
# File 'lib/discord_rda/entity/attachment.rb', line 74 def duration_formatted return nil unless duration_secs minutes = (duration_secs / 60).floor seconds = (duration_secs % 60).floor "#{minutes}:#{seconds.to_s.rjust(2, '0')}" end |
#ephemeral? ⇒ Boolean
Check if attachment is ephemeral (will be deleted)
58 59 60 |
# File 'lib/discord_rda/entity/attachment.rb', line 58 def ephemeral? ephemeral end |
#has_dimensions? ⇒ Boolean
Check if attachment has dimensions (image/video)
46 47 48 |
# File 'lib/discord_rda/entity/attachment.rb', line 46 def has_dimensions? !height.nil? && !width.nil? end |
#image? ⇒ Boolean
Check if attachment is an image
22 23 24 |
# File 'lib/discord_rda/entity/attachment.rb', line 22 def image? content_type&.start_with?('image/') end |
#size_human ⇒ String
Get file size in human readable format
64 65 66 67 68 69 70 |
# File 'lib/discord_rda/entity/attachment.rb', line 64 def size_human bytes = size.to_i return "#{bytes}B" if bytes < 1024 return "#{(bytes / 1024.0).round(1)}KB" if bytes < 1024 * 1024 return "#{(bytes / (1024.0 * 1024)).round(1)}MB" if bytes < 1024 * 1024 * 1024 "#{(bytes / (1024.0 * 1024 * 1024)).round(1)}GB" end |
#text? ⇒ Boolean
Check if attachment is a text file
40 41 42 |
# File 'lib/discord_rda/entity/attachment.rb', line 40 def text? content_type == 'text/plain' || filename.end_with?('.txt') end |
#video? ⇒ Boolean
Check if attachment is a video
28 29 30 |
# File 'lib/discord_rda/entity/attachment.rb', line 28 def video? content_type&.start_with?('video/') end |
#voice_message? ⇒ Boolean
Check if this is a voice message
84 85 86 |
# File 'lib/discord_rda/entity/attachment.rb', line 84 def !waveform.nil? || filename == 'voice-message.ogg' end |