Class: Vedeu::Colour

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from Coercions

#coerce, #coercer, included

Methods included from Common

#defined_value?, #to_sentence

Constructor Details

#initialize(attributes = {}) ⇒ Colour

Returns a new instance of Colour.

Parameters:

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

Options Hash (attributes):

  • background (String)
  • foreground (String)


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

#attributesObject (readonly)

Returns the value of attribute attributes.



13
14
15
# File 'lib/vedeu/output/colour.rb', line 13

def attributes
  @attributes
end

#backgroundObject

Returns the value of attribute background.



13
14
15
# File 'lib/vedeu/output/colour.rb', line 13

def background
  @background
end

#foregroundObject

Returns the value of attribute foreground.



13
14
15
# File 'lib/vedeu/output/colour.rb', line 13

def foreground
  @foreground
end

Instance Method Details

#defaultsHash (private)

The default values for a new instance of this class.

Returns:

  • (Hash)


59
60
61
62
63
64
# File 'lib/vedeu/output/colour.rb', line 59

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

#to_sString

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

Returns:

  • (String)


50
51
52
# File 'lib/vedeu/output/colour.rb', line 50

def to_s
  foreground.to_s + background.to_s
end