Module: Travis::Tools::SafeString

Extended by:
SafeString
Included in:
CLI::Logs, SafeString
Defined in:
lib/travis/tools/safe_string.rb

Instance Method Summary collapse

Instance Method Details

#clean(string) ⇒ Object



17
18
19
# File 'lib/travis/tools/safe_string.rb', line 17

def clean(string)
  colorized(string).gsub(/\e[^m]+m/, '')
end

#colorized(string) ⇒ Object



13
14
15
# File 'lib/travis/tools/safe_string.rb', line 13

def colorized(string)
  encoded(string).gsub(/[^[:print:]\e\n]/, '')
end

#encoded(string) ⇒ Object



6
7
8
9
10
11
# File 'lib/travis/tools/safe_string.rb', line 6

def encoded(string)
  return string unless string.respond_to? :encode
  string.encode 'utf-8'
rescue Encoding::UndefinedConversionError
  string.force_encoding 'utf-8'
end