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.
63 64 65 66 |
# File 'lib/colored2/ascii_decorator.rb', line 63 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.
31 32 33 |
# File 'lib/colored2/ascii_decorator.rb', line 31 def __background_next @__background_next end |
.__colors_disabled ⇒ Object
Returns the value of attribute __colors_disabled.
31 32 33 |
# File 'lib/colored2/ascii_decorator.rb', line 31 def __colors_disabled @__colors_disabled end |
Instance Attribute Details
#my_class ⇒ Object
Returns the value of attribute my_class.
61 62 63 |
# File 'lib/colored2/ascii_decorator.rb', line 61 def my_class @my_class end |
#string ⇒ Object
Returns the value of attribute string.
61 62 63 |
# File 'lib/colored2/ascii_decorator.rb', line 61 def string @string end |
Class Method Details
.background_next! ⇒ Object
45 46 47 |
# File 'lib/colored2/ascii_decorator.rb', line 45 def background_next! self.__background_next = true end |
.background_next? ⇒ Boolean
53 54 55 |
# File 'lib/colored2/ascii_decorator.rb', line 53 def background_next? __background_next end |
.disable! ⇒ Object
41 42 43 |
# File 'lib/colored2/ascii_decorator.rb', line 41 def disable! self.__colors_disabled = true end |
.enable! ⇒ Object
33 34 35 |
# File 'lib/colored2/ascii_decorator.rb', line 33 def enable! self.__colors_disabled = false end |
.enabled? ⇒ Boolean
37 38 39 |
# File 'lib/colored2/ascii_decorator.rb', line 37 def enabled? !__colors_disabled end |
.foreground_next! ⇒ Object
49 50 51 |
# File 'lib/colored2/ascii_decorator.rb', line 49 def foreground_next! self.__background_next = false end |
Instance Method Details
#decorate(options = {}) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/colored2/ascii_decorator.rb', line 70 def decorate( = {}) return string if !self.class.enabled? || string.empty? 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
89 90 91 |
# File 'lib/colored2/ascii_decorator.rb', line 89 def un_decorate string.gsub(/\e\[\d+(;\d+)*m/, '') end |