Class: Ask::Content::Media
Overview
Base class for media content types (Image, Audio, Video).
All have optional url, base64, mime_type, and file_id fields.
Instance Attribute Summary collapse
-
#base64 ⇒ String?
readonly
Base64-encoded media data.
-
#file_id ⇒ String?
readonly
Provider-managed file ID.
-
#mime_type ⇒ String?
readonly
MIME type.
-
#url ⇒ String?
readonly
URL of the media.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(url: nil, base64: nil, mime_type: nil, file_id: nil) ⇒ Media
constructor
A new instance of Media.
- #to_h ⇒ Object
Methods included from Block
Constructor Details
#initialize(url: nil, base64: nil, mime_type: nil, file_id: nil) ⇒ Media
Returns a new instance of Media.
101 102 103 104 105 106 107 |
# File 'lib/ask/content.rb', line 101 def initialize(url: nil, base64: nil, mime_type: nil, file_id: nil) @url = url @base64 = base64 @mime_type = mime_type @file_id = file_id freeze end |
Instance Attribute Details
#base64 ⇒ String? (readonly)
Returns Base64-encoded media data.
89 90 91 |
# File 'lib/ask/content.rb', line 89 def base64 @base64 end |
#file_id ⇒ String? (readonly)
Returns Provider-managed file ID.
95 96 97 |
# File 'lib/ask/content.rb', line 95 def file_id @file_id end |
#mime_type ⇒ String? (readonly)
Returns MIME type.
92 93 94 |
# File 'lib/ask/content.rb', line 92 def mime_type @mime_type end |
#url ⇒ String? (readonly)
Returns URL of the media.
86 87 88 |
# File 'lib/ask/content.rb', line 86 def url @url end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
109 110 111 112 |
# File 'lib/ask/content.rb', line 109 def ==(other) other.is_a?(Media) && @url == other.url && @base64 == other.base64 && @mime_type == other.mime_type && @file_id == other.file_id end |
#hash ⇒ Object
115 116 117 |
# File 'lib/ask/content.rb', line 115 def hash [@url, @base64, @mime_type, @file_id].hash end |
#to_h ⇒ Object
119 120 121 122 123 124 125 126 |
# File 'lib/ask/content.rb', line 119 def to_h h = { type: media_type } h[:url] = @url if @url h[:base64] = @base64 if @base64 h[:mime_type] = @mime_type if @mime_type h[:file_id] = @file_id if @file_id h end |