Class: Colored2::Code
- Inherits:
-
Object
- Object
- Colored2::Code
- Defined in:
- lib/colored2/codes.rb
Instance Attribute Summary collapse
-
#escape ⇒ Object
Returns the value of attribute escape.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name) ⇒ Code
constructor
A new instance of Code.
- #to_s ⇒ Object
- #value(shift = nil) ⇒ Object
Constructor Details
#initialize(name) ⇒ Code
Returns a new instance of Code.
29 30 31 32 33 34 35 |
# File 'lib/colored2/codes.rb', line 29 def initialize(name) @name = name return if name.nil? @escape = codes[name.to_sym] raise ArgumentError, "No color or effect named #{name} exists for #{self.class}." if @escape.nil? end |
Instance Attribute Details
#escape ⇒ Object
Returns the value of attribute escape.
27 28 29 |
# File 'lib/colored2/codes.rb', line 27 def escape @escape end |
#name ⇒ Object
Returns the value of attribute name.
27 28 29 |
# File 'lib/colored2/codes.rb', line 27 def name @name end |
Instance Method Details
#to_s ⇒ Object
43 44 45 |
# File 'lib/colored2/codes.rb', line 43 def to_s value end |
#value(shift = nil) ⇒ Object
37 38 39 40 41 |
# File 'lib/colored2/codes.rb', line 37 def value(shift = nil) escape_code = escape escape_code += shift if shift && escape_code name && escape ? "\e[#{escape_code}m" : '' end |