Class: Colored2::AsciiDecorator
- Inherits:
-
Object
- Object
- Colored2::AsciiDecorator
- Extended by:
- Forwardable
- Defined in:
- lib/colored2/ascii_decorator.rb
Class Attribute Summary collapse
-
.__background_next ⇒ Object
Returns the value of attribute __background_next.
-
.__colors_disabled ⇒ Object
Returns the value of attribute __colors_disabled.
Instance Attribute Summary collapse
-
#my_class ⇒ Object
Returns the value of attribute my_class.
-
#string ⇒ Object
Returns the value of attribute string.
Class Method Summary collapse
- .background_next! ⇒ Object
- .background_next? ⇒ Boolean
- .disable! ⇒ Object
- .enable! ⇒ Object
- .enabled? ⇒ Boolean
- .foreground_next! ⇒ Object
Instance Method Summary collapse
- #decorate(options = {}) ⇒ Object
-
#initialize(a_string) ⇒ AsciiDecorator
constructor
A new instance of AsciiDecorator.
- #un_decorate ⇒ Object
Constructor Details
#initialize(a_string) ⇒ AsciiDecorator
Returns a new instance of AsciiDecorator.
51 52 53 54 |
# File 'lib/colored2/ascii_decorator.rb', line 51 def initialize(a_string) self.string = a_string.instance_of?(Object) ? '' : a_string.to_s self.my_class = self.class end |
Class Attribute Details
.__background_next ⇒ Object
Returns the value of attribute __background_next.
25 26 27 |
# File 'lib/colored2/ascii_decorator.rb', line 25 def __background_next @__background_next end |
.__colors_disabled ⇒ Object
Returns the value of attribute __colors_disabled.
25 26 27 |
# File 'lib/colored2/ascii_decorator.rb', line 25 def __colors_disabled @__colors_disabled end |
Instance Attribute Details
#my_class ⇒ Object
Returns the value of attribute my_class.
49 50 51 |
# File 'lib/colored2/ascii_decorator.rb', line 49 def my_class @my_class end |
#string ⇒ Object
Returns the value of attribute string.
49 50 51 |
# File 'lib/colored2/ascii_decorator.rb', line 49 def string @string end |
Class Method Details
.background_next! ⇒ Object
35 36 37 |
# File 'lib/colored2/ascii_decorator.rb', line 35 def background_next! self.__background_next = true end |
.background_next? ⇒ Boolean
41 42 43 |
# File 'lib/colored2/ascii_decorator.rb', line 41 def background_next? self.__background_next end |
.disable! ⇒ Object
32 33 34 |
# File 'lib/colored2/ascii_decorator.rb', line 32 def disable! self.__colors_disabled = true end |
.enable! ⇒ Object
26 27 28 |
# File 'lib/colored2/ascii_decorator.rb', line 26 def enable! self.__colors_disabled = false end |
.enabled? ⇒ Boolean
29 30 31 |
# File 'lib/colored2/ascii_decorator.rb', line 29 def enabled? !self.__colors_disabled end |
.foreground_next! ⇒ Object
38 39 40 |
# File 'lib/colored2/ascii_decorator.rb', line 38 def foreground_next! self.__background_next = false end |
Instance Method Details
#decorate(options = {}) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/colored2/ascii_decorator.rb', line 58 def decorate( = {}) return string if !self.class.enabled? || string.length == 0 escape_sequence = [ Colored2::TextColor.new([:foreground]), Colored2::BackgroundColor.new([:background]), Colored2::Effect.new([:effect]) ].compact.join colored = '' colored << escape_sequence if [:beginning] == :on colored << string if [:end] colored << no_color if [:end] == :off && !colored.end_with?(no_color) colored << escape_sequence if [:end] == :on end colored end |
#un_decorate ⇒ Object
76 77 78 |
# File 'lib/colored2/ascii_decorator.rb', line 76 def un_decorate string.gsub(%r{\e\[\d+(;\d+)*m}, '') end |