Class: Ask::Content::Media

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

Overview

Base class for media content types (Image, Audio, Video). All have optional url, base64, mime_type, and file_id fields.

Direct Known Subclasses

Audio, Image, Video

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Block

#inspect

Constructor Details

#initialize(url: nil, base64: nil, mime_type: nil, file_id: nil) ⇒ Media

Returns a new instance of Media.

Parameters:

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

    URL of the media

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

    Base64-encoded data

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

    MIME type

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

    Provider-managed file ID



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

#base64String? (readonly)

Returns Base64-encoded media data.

Returns:

  • (String, nil)

    Base64-encoded media data



89
90
91
# File 'lib/ask/content.rb', line 89

def base64
  @base64
end

#file_idString? (readonly)

Returns Provider-managed file ID.

Returns:

  • (String, nil)

    Provider-managed file ID



95
96
97
# File 'lib/ask/content.rb', line 95

def file_id
  @file_id
end

#mime_typeString? (readonly)

Returns MIME type.

Returns:

  • (String, nil)

    MIME type



92
93
94
# File 'lib/ask/content.rb', line 92

def mime_type
  @mime_type
end

#urlString? (readonly)

Returns URL of the media.

Returns:

  • (String, nil)

    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

#hashObject



115
116
117
# File 'lib/ask/content.rb', line 115

def hash
  [@url, @base64, @mime_type, @file_id].hash
end

#to_hObject



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