Module: URITemplate::Utils::StringEncoding::Encode

Included in:
URITemplate::Utils::StringEncoding
Defined in:
lib/uri_template/utils.rb

Overview

Methods which do actual encoding.

Instance Method Summary collapse

Instance Method Details

#force_utf8(str) ⇒ Object

enforces UTF8 encoding

Parameters:

  • str (String)

Returns:

  • String



116
117
118
119
120
# File 'lib/uri_template/utils.rb', line 116

def force_utf8(str)
  return str if str.encoding == Encoding::UTF_8
  str = str.dup if str.frozen?
  return str.force_encoding(Encoding::UTF_8)
end

#to_ascii(str) ⇒ Object

converts a string to ascii

Parameters:

  • str (String)

Returns:

  • String



98
99
100
# File 'lib/uri_template/utils.rb', line 98

def to_ascii(str)
  str.encode(Encoding::ASCII)
end

#to_utf8(str) ⇒ Object

converts a string to utf8

Parameters:

  • str (String)

Returns:

  • String



107
108
109
# File 'lib/uri_template/utils.rb', line 107

def to_utf8(str)
  str.encode(Encoding::UTF_8)
end