module PuppetForgeServer::Utils::Encoding
Public Instance Methods
to_utf8(text)
click to toggle source
Converts give text to valid UTF-8 @param [string] text given string, can be null @return [string] output string in utf-8
# File lib/puppet_forge_server/utils/encoding.rb, line 26 def to_utf8(text) replaced = text unless replaced.nil? replaced = replaced.force_encoding("UTF-8") if is_ascii_8bit?(replaced) replaced = cleanup_utf8(replaced) end replaced end
Private Instance Methods
cleanup_utf8(text)
click to toggle source
# File lib/puppet_forge_server/utils/encoding.rb, line 41 def cleanup_utf8(text) @@ic.iconv(text) end
is_ascii_8bit?(text)
click to toggle source
# File lib/puppet_forge_server/utils/encoding.rb, line 37 def is_ascii_8bit?(text) text.encoding.name == 'ASCII-8BIT' end