Class: ChupaText::Screenshot

Inherits:
Object
  • Object
show all
Defined in:
lib/chupa-text/screenshot.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mime_type, data, encoding = nil) ⇒ Screenshot

Returns a new instance of Screenshot.



31
32
33
34
35
# File 'lib/chupa-text/screenshot.rb', line 31

def initialize(mime_type, data, encoding=nil)
  @mime_type = mime_type
  @data = data
  @encoding = encoding
end

Instance Attribute Details

#dataString (readonly)

Returns The data of the screenshot.

Returns:

  • (String)

    The data of the screenshot.



23
24
25
# File 'lib/chupa-text/screenshot.rb', line 23

def data
  @data
end

#encodingString? (readonly)

Returns The encoding of the screenshot data. nil means that the data is raw data. It's used for SVG data because it's text data. "base64" means that the data is encoded by Base64. It's used for PNG data because it's binary data.

Returns:

  • (String, nil)

    The encoding of the screenshot data. nil means that the data is raw data. It's used for SVG data because it's text data. "base64" means that the data is encoded by Base64. It's used for PNG data because it's binary data.



29
30
31
# File 'lib/chupa-text/screenshot.rb', line 29

def encoding
  @encoding
end

#mime_typeString (readonly)

Returns The MIME type of the screenshot.

Returns:

  • (String)

    The MIME type of the screenshot.



20
21
22
# File 'lib/chupa-text/screenshot.rb', line 20

def mime_type
  @mime_type
end

Instance Method Details

#decoded_dataObject



37
38
39
40
41
42
43
44
# File 'lib/chupa-text/screenshot.rb', line 37

def decoded_data
  case @encoding
  when "base64"
    @data.unpack("m*")[0]
  else
    @data
  end
end