Class: ColorString
- Inherits:
- 
      Object
      
        - Object
- ColorString
 
- Defined in:
- lib/helper/color_string.rb
Constant Summary collapse
- @@colors =
- %w(black red green yellow blue magenta cyan white) 
Class Method Summary collapse
Instance Method Summary collapse
- 
  
    
      #initialize(str, color = nil, bg = nil)  ⇒ ColorString 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of ColorString. 
- #inspect ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(str, color = nil, bg = nil) ⇒ ColorString
Returns a new instance of ColorString.
| 9 10 11 | # File 'lib/helper/color_string.rb', line 9 def initialize(str, color=nil, bg=nil) @str, @color, @bg = str, color, bg end | 
Class Method Details
.colors ⇒ Object
| 5 6 7 | # File 'lib/helper/color_string.rb', line 5 def self.colors @@colors end | 
Instance Method Details
#inspect ⇒ Object
| 21 22 23 | # File 'lib/helper/color_string.rb', line 21 def inspect "#<ColorString \"#{@str}\", color:#{@color}, bg:#{@bg}>" end | 
#to_s ⇒ Object
| 13 14 15 16 17 18 19 | # File 'lib/helper/color_string.rb', line 13 def to_s return @str if @color.nil? and @bg.nil? s = [] s << "3#{@color}" unless @color.nil? s << "4#{@bg}" unless @bg.nil? "\e[#{s.join(';')}m" << @str << "\e[0m" end |