Sha256: 8e739d649ba599a427e7f97a951e3b81369e29aae920b6ccfefb2b26f801e3aa

Contents?: true

Size: 1.18 KB

Versions: 7

Compression:

Stored size: 1.18 KB

Contents

module Vedeu

  module Colours

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

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

      # Returns a new instance of Vedeu::Colours::Repository.
      #
      # @return [Vedeu::Colours::Repository]
      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
      # sregistered.
      #
      # @param colour [String]
      # @return [Boolean]
      def registered?(colour)
        return false unless colour

        storage.key?(colour)
      end

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

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

    end # Repository

  end # Colours

end # Vedeu

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
vedeu-0.6.63 lib/vedeu/colours/repository.rb
vedeu-0.6.62 lib/vedeu/colours/repository.rb
vedeu-0.6.61 lib/vedeu/colours/repository.rb
vedeu-0.6.60 lib/vedeu/colours/repository.rb
vedeu-0.6.59 lib/vedeu/colours/repository.rb
vedeu-0.6.58 lib/vedeu/colours/repository.rb
vedeu-0.6.57 lib/vedeu/colours/repository.rb