Sha256: e9d58ecbd8e1db5c3e3e6c441b93cbea29920e1574d53cde04bd4c687d01890c

Contents?: true

Size: 1.57 KB

Versions: 40

Compression:

Stored size: 1.57 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

      # Retrieves the escape sequence of a registered colour, or
      # registers the colour with its respective escape sequence.
      #
      # @return [String]
      # @todo Unused - GL 2015-09-26
      def retrieve_or_register(colour, escape_sequence)
        if registered?(colour)
          retrieve(colour)

        else
          register(colour, escape_sequence)

        end
      end

    end # Repository

  end # Colours

end # Vedeu

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
vedeu-0.6.56 lib/vedeu/colours/repository.rb
vedeu-0.6.54 lib/vedeu/colours/repository.rb
vedeu-0.6.53 lib/vedeu/colours/repository.rb
vedeu-0.6.52 lib/vedeu/colours/repository.rb
vedeu-0.6.51 lib/vedeu/colours/repository.rb
vedeu-0.6.50 lib/vedeu/colours/repository.rb
vedeu-0.6.49 lib/vedeu/colours/repository.rb
vedeu-0.6.48 lib/vedeu/colours/repository.rb
vedeu-0.6.47 lib/vedeu/colours/repository.rb
vedeu-0.6.46 lib/vedeu/colours/repository.rb
vedeu-0.6.45 lib/vedeu/colours/repository.rb
vedeu-0.6.44 lib/vedeu/colours/repository.rb
vedeu-0.6.43 lib/vedeu/colours/repository.rb
vedeu-0.6.42 lib/vedeu/colours/repository.rb
vedeu-0.6.41 lib/vedeu/colours/repository.rb
vedeu-0.6.40 lib/vedeu/colours/repository.rb
vedeu-0.6.39 lib/vedeu/colours/repository.rb
vedeu-0.6.38 lib/vedeu/colours/repository.rb
vedeu-0.6.37 lib/vedeu/colours/repository.rb
vedeu-0.6.36 lib/vedeu/colours/repository.rb