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.
-
#replace_variables(text) ⇒ Object
Replace variables in command string.
-
#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
24 25 26 27 28 29 30 |
# File 'lib/aruba/api/text.rb', line 24 def extract_text(text) if Aruba::VERSION < '1' text.gsub(/(?:\e|\033)\[\d+(?>(;\d+)*)m/, '') else text.gsub(/(?:\e|\033)\[\d+(?>(;\d+)*)m/, '').gsub(/\\\[|\\\]/, '').gsub(/\007|\016|\017/, '') end end |
#replace_variables(text) ⇒ Object
Replace variables in command string
49 50 51 52 53 |
# File 'lib/aruba/api/text.rb', line 49 def replace_variables(text) text = text.gsub(/<pid-last-command-started>/, last_command_started.pid.to_s) if text.include? '<pid-last-command-started>' text end |
#sanitize_text(text) ⇒ Object
Unescape special characters and remove ANSI characters
36 37 38 39 40 41 |
# File 'lib/aruba/api/text.rb', line 36 def sanitize_text(text) text = unescape_text(text) text = extract_text(text) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences text.chomp end |
#unescape_text(text) ⇒ Object
Unescape text
'\n' => "\n" '\e' => "\e" '\033' => "\e" '\"' => '"'
16 17 18 |
# File 'lib/aruba/api/text.rb', line 16 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 |