Class: Vedeu::Colour

Inherits:
Object
  • Object
show all
Defined in:
lib/vedeu/models/colour.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • attributes (Hash) (defaults to: {})


12
13
14
# File 'lib/vedeu/models/colour.rb', line 12

def initialize(attributes = {})
  @attributes = defaults.merge!(attributes)
end

Instance Attribute Details

#attributesObject (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

#backgroundString

Converts the ‘:background` attribute into a terminal escape sequence.

Returns:

  • (String)


26
27
28
# File 'lib/vedeu/models/colour.rb', line 26

def background
  @background ||= Background.escape_sequence(attributes[:background])
end

#defaultsHash (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.

Returns:

  • (Hash)


42
43
44
45
46
47
# File 'lib/vedeu/models/colour.rb', line 42

def defaults
  {
    foreground: '',
    background: ''
  }
end

#foregroundString

Converts the ‘:foreground` attribute into a terminal escape sequence.

Returns:

  • (String)


19
20
21
# File 'lib/vedeu/models/colour.rb', line 19

def foreground
  @foreground ||= Foreground.escape_sequence(attributes[:foreground])
end

#to_sString

Returns both or either of the converted attributes into a single escape sequence.

Returns:

  • (String)


34
35
36
# File 'lib/vedeu/models/colour.rb', line 34

def to_s
  foreground + background
end