Class: Test::Unit::Color
- Inherits:
-
Object
- Object
- Test::Unit::Color
- Defined in:
- lib/test/unit/color.rb
Constant Summary collapse
- NAMES =
["black", "red", "green", "yellow", "blue", "magenta", "cyan", "white"]
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #+(other) ⇒ Object
- #==(other) ⇒ Object
- #bold? ⇒ Boolean
- #escape_sequence ⇒ Object
- #foreground? ⇒ Boolean
-
#initialize(name, options = {}) ⇒ Color
constructor
A new instance of Color.
- #intensity? ⇒ Boolean
- #italic? ⇒ Boolean
- #sequence ⇒ Object
- #underline? ⇒ Boolean
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, ={}) @name = name @foreground = [:foreground] @foreground = true if @foreground.nil? @intensity = [:intensity] @bold = [:bold] @italic = [:italic] @underline = [:underline] end |
Instance Attribute Details
#name ⇒ Object (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
26 27 28 |
# File 'lib/test/unit/color.rb', line 26 def bold? @bold end |
#escape_sequence ⇒ Object
62 63 64 |
# File 'lib/test/unit/color.rb', line 62 def escape_sequence "\e[#{sequence.join(';')}m" end |
#foreground? ⇒ Boolean
18 19 20 |
# File 'lib/test/unit/color.rb', line 18 def foreground? @foreground end |
#intensity? ⇒ Boolean
22 23 24 |
# File 'lib/test/unit/color.rb', line 22 def intensity? @intensity end |
#italic? ⇒ Boolean
30 31 32 |
# File 'lib/test/unit/color.rb', line 30 def italic? @italic end |
#sequence ⇒ Object
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
34 35 36 |
# File 'lib/test/unit/color.rb', line 34 def underline? @underline end |