Sha256: daf1d2c341999d98c6e4ab8ff9ef2c6ed80e6cc456c7a754b28c514a5fb3f241

Contents?: true

Size: 1.25 KB

Versions: 4

Compression:

Stored size: 1.25 KB

Contents

module Vedeu

  # Allows the storing of HTML/CSS colours and their respective escape
  # sequences.
  class Colours

    # @!attribute [r] storage
    # @return [Hash<String => String>]
    attr_reader :storage

    # Returns a new instance of Vedeu::Colours.
    #
    # @return [Vedeu::Colours]
    def initialize
      @storage = {}
    end

    # Registers a colour with respective escape sequence.
    #
    # @return [String]
    def register(colour, escape_sequence)
      storage.store(colour, escape_sequence)
    end

    # Returns a boolean indicating whether the colour has been registered.
    #
    # @return [Boolean]
    def registered?(colour)
      storage.key?(colour)
    end

    # Removes all stored colours.
    #
    # @return [Hash]
    def reset!
      storage.clear
    end

    # Retrieves a registered colour.
    #
    # @return [String]
    def retrieve(colour)
      storage.fetch(colour, '')
    end

    # Retrieves a registered colour, or registers the colour with its respective
    # escape sequence.
    #
    # @return [String]
    def retrieve_or_register(colour, escape_sequence)
      if registered?(colour)
        retrieve(colour)

      else
        register(colour, escape_sequence)

      end
    end

  end # Colours

end # Vedeu

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
vedeu-0.4.22 lib/vedeu/repositories/repositories/colours.rb
vedeu-0.4.21 lib/vedeu/repositories/repositories/colours.rb
vedeu-0.4.20 lib/vedeu/repositories/repositories/colours.rb
vedeu-0.4.19 lib/vedeu/repositories/repositories/colours.rb