Class: Intelligence::MessageContent::Binary

Inherits:
Base
  • Object
show all
Defined in:
lib/intelligence/message_content/binary.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Intelligence::MessageContent::Base

Instance Attribute Details

#bytesObject (readonly)

Returns the value of attribute bytes.



12
13
14
# File 'lib/intelligence/message_content/binary.rb', line 12

def bytes
  @bytes
end

#content_typeObject (readonly)

Returns the value of attribute content_type.



11
12
13
# File 'lib/intelligence/message_content/binary.rb', line 11

def content_type
  @content_type
end

Instance Method Details

#image?Boolean

Returns:

  • (Boolean)


19
20
21
22
# File 'lib/intelligence/message_content/binary.rb', line 19

def image?
  ( @content_type || false ) && 
  ( MIME::Types[ @content_type ]&.first&.media_type == 'image' )
end

#to_hObject



24
25
26
# File 'lib/intelligence/message_content/binary.rb', line 24

def to_h
  { type: :binary, content_type: content_type, bytes: bytes }
end

#valid?Boolean

Returns:

  • (Boolean)


14
15
16
17
# File 'lib/intelligence/message_content/binary.rb', line 14

def valid?
  ( @content_type || false ) && !MIME::Types[ @content_type ].empty? && 
  ( @bytes || false ) && bytes.respond_to?( :empty? ) && !bytes.empty? 
end