Class: Test::Unit::Color
Relationships & Source Files | |
Namespace Children | |
Exceptions:
| |
Inherits: | Object |
Defined in: | lib/test/unit/color.rb |
Constant Summary
-
NAMES =
# File 'lib/test/unit/color.rb', line 24["black", "red", "green", "yellow", "blue", "magenta", "cyan", "white"]
Class Method Summary
Instance Attribute Summary
- #background? ⇒ Boolean readonly
- #bold? ⇒ Boolean readonly
- #foreground? ⇒ Boolean readonly
- #intensity? ⇒ Boolean readonly
- #italic? ⇒ Boolean readonly
- #name readonly
- #underline? ⇒ Boolean readonly
Instance Method Summary
Constructor Details
.new(name, options = {}) ⇒ Color
# File 'lib/test/unit/color.rb', line 28
def initialize(name, ={}) @name = name if .has_key?(:foreground) if [:foreground].nil? @background = false else @background = ! [:foreground] end else @background = [:background] end @intensity = [:intensity] @bold = [:bold] @italic = [:italic] @underline = [:underline] end
Class Method Details
.parse_256_color(string)
[ GitHub ]# File 'lib/test/unit/color.rb', line 11
def parse_256_color(string) case string when /\A([0-5])([0-5])([0-5])\z/ red, green, blue = $1, $2, $3 red.to_i * 36 + green.to_i * 6 + blue.to_i + 16 else = "must be 'RGB' format and R, G and B " + "are in 0-5: #{string.inspect}" raise ParseError, end end
Instance Attribute Details
#background? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/test/unit/color.rb', line 49
def background? @background end
#bold? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/test/unit/color.rb', line 57
def bold? @bold end
#foreground? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/test/unit/color.rb', line 45
def foreground? not background? end
#intensity? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/test/unit/color.rb', line 53
def intensity? @intensity end
#italic? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/test/unit/color.rb', line 61
def italic? @italic end
#name (readonly)
[ GitHub ]# File 'lib/test/unit/color.rb', line 27
attr_reader :name
#underline? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/test/unit/color.rb', line 65
def underline? @underline end
Instance Method Details
#+(other)
[ GitHub ]#==(other)
[ GitHub ]# File 'lib/test/unit/color.rb', line 69
def ==(other) self.class === other and [name, background?, intensity?, bold?, italic?, underline?] == [other.name, other.background?, other.intensity?, other.bold?, other.italic?, other.underline?] end
#escape_sequence
[ GitHub ]# File 'lib/test/unit/color.rb', line 100
def escape_sequence "\e[#{sequence.join(';')}m" end
#sequence
[ GitHub ]# File 'lib/test/unit/color.rb', line 77
def sequence sequence = [] if @name == "none" elsif @name == "reset" sequence << "0" else if NAMES.include?(@name) color_parameter = foreground? ? 3 : 4 color_parameter += 6 if intensity? color = NAMES.index(@name) sequence << "#{color_parameter}#{color}" else sequence << (foreground? ? "38" : "48") sequence << "5" sequence << self.class.parse_256_color(@name).to_s end end sequence << "1" if bold? sequence << "3" if italic? sequence << "4" if underline? sequence end