Module: OllamaChat::Utils::UTF8Converter

Included in:
Chat, PNGMetadataExtractor, PNGMetadataExtractor
Defined in:
lib/ollama_chat/utils/utf8_converter.rb

Overview

A utility module for converting strings to UTF-8 encoding. This module provides methods to ensure text is properly encoded as UTF-8, replacing invalid or undefined characters to prevent encoding errors.

Instance Method Summary collapse

Instance Method Details

#convert_to_utf8(text) ⇒ String?

Converts the given text to UTF-8 encoding, replacing invalid or undefined characters.

Parameters:

  • text (String, nil)

    the text to be converted if any

Returns:

  • (String, nil)

    the UTF-8 encoded string or nil



10
11
12
# File 'lib/ollama_chat/utils/utf8_converter.rb', line 10

def convert_to_utf8(text)
  text&.encode('UTF-8', invalid: :replace, undef: :replace)
end