Class: CLAide::ANSI::StringEscaper
- Defined in:
- lib/claide/ansi/string_escaper.rb
Overview
Provides support to wrap strings in ANSI sequences according to the
ANSI.disabled
setting.
Instance Method Summary collapse
- #apply(*keys) ⇒ StringEscaper
-
#initialize(string) ⇒ StringEscaper
constructor
A new instance of StringEscaper.
-
#wrap_in_ansi_sequence(open, close) ⇒ StringEscaper
Wraps a string in the given ANSI sequences, taking care of handling existing sequences for the same family of attributes (i.e. attributes terminated by the same sequence).
Methods inherited from String
Constructor Details
#initialize(string) ⇒ StringEscaper
Returns a new instance of StringEscaper.
9 10 11 |
# File 'lib/claide/ansi/string_escaper.rb', line 9 def initialize(string) super end |
Instance Method Details
#apply(*keys) ⇒ StringEscaper
33 34 35 36 37 38 |
# File 'lib/claide/ansi/string_escaper.rb', line 33 def apply(*keys) keys.flatten.each do |key| send(key) end self end |
#wrap_in_ansi_sequence(open, close) ⇒ StringEscaper
Returns Wraps a string in the given ANSI sequences, taking care of handling existing sequences for the same family of attributes (i.e. attributes terminated by the same sequence).
18 19 20 21 22 23 24 25 |
# File 'lib/claide/ansi/string_escaper.rb', line 18 def wrap_in_ansi_sequence(open, close) if ANSI.disabled self else gsub!(close, open) insert(0, open).insert(-1, close) end end |