Class: Ask::Content::File
Overview
A file block within a multi-modal message.
Carries inline data by default; url or file_id can be used
instead when the file lives somewhere the provider can reach.
Instance Attribute Summary collapse
-
#data ⇒ String?
readonly
Raw file content.
-
#file_id ⇒ String?
readonly
Provider-managed file ID.
-
#filename ⇒ String?
readonly
Original filename.
-
#mime_type ⇒ String?
readonly
MIME type.
-
#url ⇒ String?
readonly
URL of the file.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(data: nil, mime_type: nil, filename: nil, url: nil, file_id: nil) ⇒ File
constructor
A new instance of File.
- #to_h ⇒ Object
Methods included from Block
Constructor Details
#initialize(data: nil, mime_type: nil, filename: nil, url: nil, file_id: nil) ⇒ File
Returns a new instance of File.
189 190 191 192 193 194 195 196 |
# File 'lib/ask/content.rb', line 189 def initialize(data: nil, mime_type: nil, filename: nil, url: nil, file_id: nil) @data = data @mime_type = mime_type @filename = filename @url = url @file_id = file_id freeze end |
Instance Attribute Details
#data ⇒ String? (readonly)
Returns raw file content.
170 171 172 |
# File 'lib/ask/content.rb', line 170 def data @data end |
#file_id ⇒ String? (readonly)
Returns Provider-managed file ID.
182 183 184 |
# File 'lib/ask/content.rb', line 182 def file_id @file_id end |
#filename ⇒ String? (readonly)
Returns original filename.
176 177 178 |
# File 'lib/ask/content.rb', line 176 def filename @filename end |
#mime_type ⇒ String? (readonly)
Returns MIME type.
173 174 175 |
# File 'lib/ask/content.rb', line 173 def mime_type @mime_type end |
#url ⇒ String? (readonly)
Returns URL of the file.
179 180 181 |
# File 'lib/ask/content.rb', line 179 def url @url end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
198 199 200 201 |
# File 'lib/ask/content.rb', line 198 def ==(other) other.is_a?(File) && @data == other.data && @mime_type == other.mime_type && @filename == other.filename && @url == other.url && @file_id == other.file_id end |
#hash ⇒ Object
204 205 206 |
# File 'lib/ask/content.rb', line 204 def hash [@data, @mime_type, @filename, @url, @file_id].hash end |
#to_h ⇒ Object
208 209 210 211 212 213 214 215 216 |
# File 'lib/ask/content.rb', line 208 def to_h h = { type: "file" } h[:data] = @data if @data h[:mime_type] = @mime_type if @mime_type h[:filename] = @filename if @filename h[:url] = @url if @url h[:file_id] = @file_id if @file_id h end |