Module: Aruba::Api::Text
- Included in:
- Aruba::Api
- Defined in:
- lib/aruba/api/text.rb
Overview
Text manipulation
Instance Method Summary collapse
-
#extract_text(text) ⇒ Object
Remove ansi characters from text.
-
#sanitize_text(text) ⇒ Object
Unescape special characters and remove ANSI characters.
-
#unescape_text(text) ⇒ Object
Unescape text.
Instance Method Details
#extract_text(text) ⇒ Object
Remove ansi characters from text
33 34 35 36 37 38 |
# File 'lib/aruba/api/text.rb', line 33 def extract_text(text) text .gsub(/(?:\e|\033)\[\d+(?>(;\d+)*)m/, '') .gsub(/\\\[|\\\]/, '') .gsub(/\007|\016|\017/, '') end |
#sanitize_text(text) ⇒ Object
Unescape special characters and remove ANSI characters
44 45 46 47 48 49 |
# File 'lib/aruba/api/text.rb', line 44 def sanitize_text(text) text = unescape_text(text) text = extract_text(text) if aruba.config.remove_ansi_escape_sequences text.chomp end |
#unescape_text(text) ⇒ Object
Unescape text
‘n’ => “n” ‘e’ => “e” ‘033’ => “e” ‘"’ => ‘“’
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/aruba/api/text.rb', line 18 def unescape_text(text) text .gsub('\n', "\n") .gsub('\"', '"') .gsub('\e', "\e") .gsub('\033', "\e") .gsub('\016', "\016") .gsub('\017', "\017") .gsub('\t', "\t") end |