Class: Vedeu::Colour
- Inherits:
-
Object
- Object
- Vedeu::Colour
- Includes:
- Coercions
- Defined in:
- lib/vedeu/output/colour.rb
Overview
Provides a container for terminal escape sequences controlling the foreground and background colours of a character or collection of characters.
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#background ⇒ Object
Returns the value of attribute background.
-
#foreground ⇒ Object
Returns the value of attribute foreground.
Instance Method Summary collapse
-
#defaults ⇒ Hash
private
The default values for a new instance of this class.
-
#initialize(attributes = {}) ⇒ Colour
constructor
Returns a new instance of Colour.
-
#to_s ⇒ String
Returns both or either of the converted attributes into a single escape sequence.
Methods included from Coercions
Methods included from Common
Constructor Details
#initialize(attributes = {}) ⇒ Colour
Returns a new instance of Colour.
23 24 25 26 27 28 |
# File 'lib/vedeu/output/colour.rb', line 23 def initialize(attributes = {}) @attributes = defaults.merge!(attributes) @background = Background.coerce(@attributes[:background]) @foreground = Foreground.coerce(@attributes[:foreground]) end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
13 14 15 |
# File 'lib/vedeu/output/colour.rb', line 13 def attributes @attributes end |
#background ⇒ Object
Returns the value of attribute background.
13 14 15 |
# File 'lib/vedeu/output/colour.rb', line 13 def background @background end |
#foreground ⇒ Object
Returns the value of attribute foreground.
13 14 15 |
# File 'lib/vedeu/output/colour.rb', line 13 def foreground @foreground end |
Instance Method Details
#defaults ⇒ Hash (private)
The default values for a new instance of this class.
59 60 61 62 63 64 |
# File 'lib/vedeu/output/colour.rb', line 59 def defaults { foreground: '', background: '' } end |
#to_s ⇒ String
Returns both or either of the converted attributes into a single escape sequence.
50 51 52 |
# File 'lib/vedeu/output/colour.rb', line 50 def to_s foreground.to_s + background.to_s end |