Sha256: 2af5056d7c4bfae7e8ac2bc2a219e4b59ac6c6b85fe560f3f9c08b77c863f2d0

Contents?: true

Size: 906 Bytes

Versions: 1

Compression:

Stored size: 906 Bytes

Contents

module Vedeu
  class Colour

    attr_reader :attributes

    # @param attributes [Hash]
    # @return [Colour]
    def initialize(attributes = {})
      @attributes = defaults.merge!(attributes)
    end

    # Converts the `:foreground` attribute into a terminal escape sequence.
    #
    # @return [String]
    def foreground
      @foreground ||= Foreground.escape_sequence(attributes[:foreground])
    end

    # Converts the `:background` attribute into a terminal escape sequence.
    #
    # @return [String]
    def background
      @background ||= Background.escape_sequence(attributes[:background])
    end

    # Returns both or either of the converted attributes into a single escape
    # sequence.
    #
    # @return [String]
    def to_s
      foreground + background
    end

    private

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

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vedeu-0.1.17 lib/vedeu/models/colour.rb