Class: Test::Unit::Color

Inherits:
Object
  • Object
show all
Defined in:
lib/test/unit/color.rb

Constant Summary collapse

NAMES =
["black", "red", "green", "yellow",
"blue", "magenta", "cyan", "white"]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Color

Returns a new instance of Color.



8
9
10
11
12
13
14
15
16
# File 'lib/test/unit/color.rb', line 8

def initialize(name, options={})
  @name = name
  @foreground = options[:foreground]
  @foreground = true if @foreground.nil?
  @intensity = options[:intensity]
  @bold = options[:bold]
  @italic = options[:italic]
  @underline = options[:underline]
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/test/unit/color.rb', line 7

def name
  @name
end

Instance Method Details

#+(other) ⇒ Object



66
67
68
# File 'lib/test/unit/color.rb', line 66

def +(other)
  MixColor.new([self, other])
end

#==(other) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/test/unit/color.rb', line 38

def ==(other)
  self.class === other and
    [name, foreground?, intensity?,
     bold?, italic?, underline?] ==
    [other.name, other.foreground?, other.intensity?,
     other.bold?, other.italic?, other.underline?]
end

#bold?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/test/unit/color.rb', line 26

def bold?
  @bold
end

#escape_sequenceObject



62
63
64
# File 'lib/test/unit/color.rb', line 62

def escape_sequence
  "\e[#{sequence.join(';')}m"
end

#foreground?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/test/unit/color.rb', line 18

def foreground?
  @foreground
end

#intensity?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/test/unit/color.rb', line 22

def intensity?
  @intensity
end

#italic?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/test/unit/color.rb', line 30

def italic?
  @italic
end

#sequenceObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/test/unit/color.rb', line 46

def sequence
  sequence = []
  if @name == "none"
  elsif @name == "reset"
    sequence << "0"
  else
    foreground_parameter = foreground? ? 3 : 4
    foreground_parameter += 6 if intensity?
    sequence << "#{foreground_parameter}#{NAMES.index(@name)}"
  end
  sequence << "1" if bold?
  sequence << "3" if italic?
  sequence << "4" if underline?
  sequence
end

#underline?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/test/unit/color.rb', line 34

def underline?
  @underline
end