Class: Ask::Content::File

Inherits:
Object
  • Object
show all
Includes:
Block
Defined in:
lib/ask/content.rb

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

Instance Method Summary collapse

Methods included from Block

#inspect

Constructor Details

#initialize(data: nil, mime_type: nil, filename: nil, url: nil, file_id: nil) ⇒ File

Returns a new instance of File.

Parameters:

  • data (String, nil) (defaults to: nil)

    raw file content

  • mime_type (String, nil) (defaults to: nil)

    MIME type

  • filename (String, nil) (defaults to: nil)

    original filename

  • url (String, nil) (defaults to: nil)

    URL of the file

  • file_id (String, nil) (defaults to: nil)

    Provider-managed file ID



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

#dataString? (readonly)

Returns raw file content.

Returns:

  • (String, nil)

    raw file content



170
171
172
# File 'lib/ask/content.rb', line 170

def data
  @data
end

#file_idString? (readonly)

Returns Provider-managed file ID.

Returns:

  • (String, nil)

    Provider-managed file ID



182
183
184
# File 'lib/ask/content.rb', line 182

def file_id
  @file_id
end

#filenameString? (readonly)

Returns original filename.

Returns:

  • (String, nil)

    original filename



176
177
178
# File 'lib/ask/content.rb', line 176

def filename
  @filename
end

#mime_typeString? (readonly)

Returns MIME type.

Returns:

  • (String, nil)

    MIME type



173
174
175
# File 'lib/ask/content.rb', line 173

def mime_type
  @mime_type
end

#urlString? (readonly)

Returns URL of the file.

Returns:

  • (String, nil)

    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

#hashObject



204
205
206
# File 'lib/ask/content.rb', line 204

def hash
  [@data, @mime_type, @filename, @url, @file_id].hash
end

#to_hObject



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