Sha256: 2303515686be2c231336ad887f01de5b1a512f54eb7e49e5924769d7ea7bacc3

Contents?: true

Size: 1.24 KB

Versions: 6

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

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
      alias_method :all, :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

6 entries across 6 versions & 1 rubygems

Version Path
vedeu-0.8.6 lib/vedeu/colours/repository.rb
vedeu-0.8.5 lib/vedeu/colours/repository.rb
vedeu-0.8.4 lib/vedeu/colours/repository.rb
vedeu-0.8.3 lib/vedeu/colours/repository.rb
vedeu-0.8.2 lib/vedeu/colours/repository.rb
vedeu-0.8.1 lib/vedeu/colours/repository.rb