Method: Rsmart::ETL.encode

Defined in:
lib/rsmart_toolbox/etl.rb

.encode(str, opt = { encoding: "UTF-8" }) ⇒ String

Encodes the input String and replaces invalid or undefined characters.

Parameters:

  • str (String)

    the String to be encoded and invalid characters replaced with valid characters.

  • opt (Hash) (defaults to: { encoding: "UTF-8" })

    a customizable set of options

Options Hash (opt):

  • :encoding (String)

    the character encoding to use.

Returns:

  • (String)

    the result of encoding the String and replacing invalid characters with valid characters.

See Also:

  • String#encode


108
109
110
111
112
# File 'lib/rsmart_toolbox/etl.rb', line 108

def self.encode(str, opt={ encoding: "UTF-8" } )
  opt[:encoding] = "UTF-8" if opt[:encoding].nil?
  str.encode( opt[:encoding], :invalid => :replace,
              :undef => :replace, :replace => "" )
end