Class: Kojak::Printer::Colorized

Inherits:
Synchronized show all
Defined in:
lib/kojak/printer/colorized.rb

Overview

Internal: Special version of thread-safe printer that additionally colorizes the output with one preconfigured color.

Direct Known Subclasses

RandomlyColorized

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Kojak::Printer

#puts

Constructor Details

#initialize(out, color = :white) ⇒ Colorized

Public: Constructor. Configures printer to write to given output in specified color.

out - The Stream to write data to. color - The String or Symbol with name of the color to use.

Returns nothing.



17
18
19
20
21
22
# File 'lib/kojak/printer/colorized.rb', line 17

def initialize(out, color = :white)
  super(out)

  @color   = color
  @rainbow = Rainbow.new
end

Instance Attribute Details

#colorObject

Public: The String or Symbol with name of the assigned color.



8
9
10
# File 'lib/kojak/printer/colorized.rb', line 8

def color
  @color
end

Instance Method Details

#write(s, *args) ⇒ Object



24
25
26
# File 'lib/kojak/printer/colorized.rb', line 24

def write(s, *args)
  super(@rainbow.wrap(s.to_s).color(color), *args)
end