Class: Vedeu::Colour
- Inherits:
-
Object
- Object
- Vedeu::Colour
- Defined in:
- lib/vedeu/models/colour.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Instance Method Summary collapse
-
#background ⇒ String
Converts the ‘:background` attribute into a terminal escape sequence.
- #defaults ⇒ Hash private private
-
#foreground ⇒ String
Converts the ‘:foreground` attribute into a terminal escape sequence.
-
#initialize(attributes = {}) ⇒ Colour
constructor
Initialises a new Colour object which is a container terminal escape sequences controlling the foreground and background colour of a character or collection of characters.
-
#to_s ⇒ String
Returns both or either of the converted attributes into a single escape sequence.
Constructor Details
#initialize(attributes = {}) ⇒ Colour
Initialises a new Colour object which is a container terminal escape sequences controlling the foreground and background colour of a character or collection of characters.
12 13 14 |
# File 'lib/vedeu/models/colour.rb', line 12 def initialize(attributes = {}) @attributes = defaults.merge!(attributes) end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
4 5 6 |
# File 'lib/vedeu/models/colour.rb', line 4 def attributes @attributes end |
Instance Method Details
#background ⇒ String
Converts the ‘:background` attribute into a terminal escape sequence.
26 27 28 |
# File 'lib/vedeu/models/colour.rb', line 26 def background @background ||= Background.escape_sequence(attributes[:background]) end |
#defaults ⇒ Hash (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
42 43 44 45 46 47 |
# File 'lib/vedeu/models/colour.rb', line 42 def defaults { foreground: '', background: '' } end |
#foreground ⇒ String
Converts the ‘:foreground` attribute into a terminal escape sequence.
19 20 21 |
# File 'lib/vedeu/models/colour.rb', line 19 def foreground @foreground ||= Foreground.escape_sequence(attributes[:foreground]) end |
#to_s ⇒ String
Returns both or either of the converted attributes into a single escape sequence.
34 35 36 |
# File 'lib/vedeu/models/colour.rb', line 34 def to_s foreground + background end |