Module: Mindee::Input::Source

Defined in:
lib/mindee.rb,
lib/mindee/input/sources.rb

Overview

Document source handling.

Defined Under Namespace

Classes: Base64InputSource, BytesInputSource, FileInputSource, InvalidMimeTypeError, LocalInputSource, MimeTypeError, PathInputSource, UnfixablePDFError, UrlInputSource

Constant Summary collapse

ALLOWED_MIME_TYPES =

Mime types accepted by the server.

[
  'application/pdf',
  'image/heic',
  'image/png',
  'image/jpeg',
  'image/tiff',
  'image/webp',
].freeze

Class Method Summary collapse

Class Method Details

.convert_to_unicode_escape(string) ⇒ Object

Replaces non-ASCII characters by their unicode escape sequence. Keeps other characters as is.

Returns:

  • A clean String.



237
238
239
240
241
242
243
244
245
246
247
# File 'lib/mindee/input/sources.rb', line 237

def self.convert_to_unicode_escape(string)
  unicode_escape_string = ''.dup
  string.each_char do |char|
    unicode_escape_string << if char.bytesize > 1
                               "\\u#{char.unpack1('U').to_s(16).rjust(4, '0')}"
                             else
                               char
                             end
  end
  unicode_escape_string
end