Class: Discorb::Image
- Inherits:
-
Object
- Object
- Discorb::Image
- Defined in:
- lib/discorb/image.rb
Overview
Represents an image.
Instance Method Summary collapse
-
#initialize(source, type = nil) -> Image
constructor
Initializes a new Image.
- #inspect -> Object
-
#to_s -> String
Formats the image as a Discord style.
Constructor Details
#initialize(source, type = nil) -> Image
Initializes a new Image.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/discorb/image.rb', line 17 def initialize(source, type = nil) if source.respond_to?(:read) @io = source @type = type || MIME::Types.type_for(source.path).first.content_type elsif ::File.exist?(source) @io = ::File.open(source, "rb") @type = MIME::Types.type_for(source).first.to_s else raise ArgumentError, "Couldn't read file." end end |
Instance Method Details
#inspect -> Object
38 39 40 |
# File 'lib/discorb/image.rb', line 38 def inspect "#<#{self.class} #{@type}>" end |
#to_s -> String
Formats the image as a Discord style.
34 35 36 |
# File 'lib/discorb/image.rb', line 34 def to_s "data:#{@type};base64,#{Base64.strict_encode64(@io.read)}" end |