Class: Test::Unit::ColorScheme

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/test/unit/color-scheme.rb

Constant Summary collapse

@@default =
nil
@@schemes =
{}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scheme_spec) ⇒ ColorScheme

Returns a new instance of ColorScheme.



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

def initialize(scheme_spec)
  @scheme = {}
  scheme_spec.each do |key, color_spec|
    self[key] = color_spec
  end
end

Class Method Details

.[](id) ⇒ Object



25
26
27
# File 'lib/test/unit/color-scheme.rb', line 25

def [](id)
  @@schemes[id.to_s]
end

.[]=(id, scheme_or_spec) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/test/unit/color-scheme.rb', line 29

def []=(id, scheme_or_spec)
  if scheme_or_spec.is_a?(self)
    scheme = scheme_or_spec
  else
    scheme = new(scheme_or_spec)
  end
  @@schemes[id.to_s] = scheme
end

.allObject



21
22
23
# File 'lib/test/unit/color-scheme.rb', line 21

def all
  @@schemes.merge("default" => default)
end

.defaultObject



10
11
12
13
14
15
16
17
18
# File 'lib/test/unit/color-scheme.rb', line 10

def default
  @@default ||= new("success" => Color.new("green", :bold => true),
                    "failure" => Color.new("red", :bold => true),
                    "pending" => Color.new("magenta", :bold => true),
                    "omission" => Color.new("blue", :bold => true),
                    "notification" => Color.new("cyan", :bold => true),
                    "error" => Color.new("yellow", :bold => true) +
                               Color.new("black", :foreground => false))
end

Instance Method Details

#[](name) ⇒ Object



46
47
48
# File 'lib/test/unit/color-scheme.rb', line 46

def [](name)
  @scheme[name.to_s]
end

#[]=(name, color_spec) ⇒ Object



50
51
52
# File 'lib/test/unit/color-scheme.rb', line 50

def []=(name, color_spec)
  @scheme[name.to_s] = make_color(color_spec)
end

#each(&block) ⇒ Object



54
55
56
# File 'lib/test/unit/color-scheme.rb', line 54

def each(&block)
  @scheme.each(&block)
end

#to_hashObject



58
59
60
61
62
63
64
# File 'lib/test/unit/color-scheme.rb', line 58

def to_hash
  hash = {}
  @scheme.each do |key, color|
    hash[key] = color
  end
  hash
end