Class: Testbot::Runner::SafeResultText
- Inherits:
-
Object
- Object
- Testbot::Runner::SafeResultText
- Defined in:
- lib/runner/safe_result_text.rb
Class Method Summary collapse
Class Method Details
.clean(text) ⇒ Object
5 6 7 |
# File 'lib/runner/safe_result_text.rb', line 5 def self.clean(text) clean_escape_sequences(strip_invalid_utf8(text)) end |
.clean_escape_sequences(text) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/runner/safe_result_text.rb', line 15 def self.clean_escape_sequences(text) tail_marker = "^[[0m" tail = text.rindex(tail_marker) && text[text.rindex(tail_marker)+tail_marker.length..-1] if !tail text elsif tail.include?("^[[") && !tail.include?("m") text[0..text.rindex(tail_marker) + tail_marker.length - 1] elsif text.scan(/\[.*?m/).last != tail_marker text[0..text.rindex(tail_marker) + tail_marker.length - 1] else text end end |
.strip_invalid_utf8(text) ⇒ Object
9 10 11 12 13 |
# File 'lib/runner/safe_result_text.rb', line 9 def self.strip_invalid_utf8(text) # http://po-ru.com/diary/fixing-invalid-utf-8-in-ruby-revisited/ ic = Iconv.new('UTF-8//IGNORE', 'UTF-8') ic.iconv(text + ' ')[0..-2] end |