Class: Intelligence::MessageContent::File
- Defined in:
- lib/intelligence/message_content/file.rb
Instance Method Summary collapse
- #content_type ⇒ Object
-
#initialize(attributes) ⇒ File
constructor
A new instance of File.
- #to_h ⇒ Object
- #valid? ⇒ Boolean
- #valid_uri?(schemes = [ 'http', 'https' ]) ⇒ Boolean
Constructor Details
#initialize(attributes) ⇒ File
Returns a new instance of File.
11 12 13 14 |
# File 'lib/intelligence/message_content/file.rb', line 11 def initialize( attributes ) @uri = URI( attributes[ :uri ] ) if attributes[ :uri ] @content_type = attributes[ :content_type ] end |
Instance Method Details
#content_type ⇒ Object
16 17 18 |
# File 'lib/intelligence/message_content/file.rb', line 16 def content_type @content_type ||= valid_uri? ? MIME::Types.type_for( @uri.path )&.first&.content_type : nil end |
#to_h ⇒ Object
28 29 30 |
# File 'lib/intelligence/message_content/file.rb', line 28 def to_h { type: :file, content_type: content_type, uri: @uri.to_s } end |
#valid? ⇒ Boolean
24 25 26 |
# File 'lib/intelligence/message_content/file.rb', line 24 def valid? valid_uri? && !MIME::Types[ content_type ].empty? end |
#valid_uri?(schemes = [ 'http', 'https' ]) ⇒ Boolean
20 21 22 |
# File 'lib/intelligence/message_content/file.rb', line 20 def valid_uri?( schemes = [ 'http', 'https' ] ) !!( @uri && schemes.include?( @uri.scheme ) && @uri.path && !@uri.path.empty? ) end |