module Nuggets::Env::UserEncodingMixin

Public Instance Methods

user_encoding → aString click to toggle source

Finds the user's selected encoding.

# File lib/nuggets/env/user_encoding_mixin.rb, line 40
def user_encoding(default = 'UTF-8')
  self['ENCODING'] || begin
    lang = self['LANG']
    lang[/\.(.*)/, 1] if lang
  end || if defined?(::Win32::Console)
    "CP#{::Win32::Console.InputCP}"
  elsif ::File::ALT_SEPARATOR
    cp = %x{chcp}[/:\s*(.*?)\./, 1]
    "CP#{cp}" if cp
  end || default
end