Sha256: f6a2be227fa3968b483f0cdd3c9e0e1a3b6b10eba9f776a18fc3634d5a826064

Contents?: true

Size: 835 Bytes

Versions: 9

Compression:

Stored size: 835 Bytes

Contents

# coding: utf-8

require 'equatable'

module Pastel
  # Collects a list of decorators for styling a string
  #
  # @api private
  class DecoratorChain
    include Enumerable
    include Equatable

    def initialize(decorators = [])
      @decorators = decorators
    end

    # Add decorator
    #
    # @api public
    def add(decorator)
      if decorators.include?(decorator)
        self.class.new(decorators)
      else
        self.class.new(decorators + [decorator])
      end
    end

    # Iterate over list of decorators
    #
    # @api public
    def each(&block)
      decorators.each(&block)
    end

    # Create an empty decorator chain
    #
    # @return [DecoratorChain]
    #
    # @api public
    def self.empty
      new([])
    end

    protected

    attr_reader :decorators
  end # DecoratorChain
end # Patel

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
pastel-0.7.4 lib/pastel/decorator_chain.rb
pokedex-terminal-0.2.8 vendor/bundle/ruby/2.7.0/gems/pastel-0.7.3/lib/pastel/decorator_chain.rb
pokedex-terminal-0.2.7 vendor/bundle/ruby/2.7.0/gems/pastel-0.7.3/lib/pastel/decorator_chain.rb
pokedex-terminal-0.2.6 vendor/bundle/ruby/2.7.0/gems/pastel-0.7.3/lib/pastel/decorator_chain.rb
pokedex-terminal-0.2.5 vendor/bundle/ruby/2.7.0/gems/pastel-0.7.3/lib/pastel/decorator_chain.rb
pokedex-terminal-0.2.4 vendor/bundle/ruby/2.7.0/gems/pastel-0.7.3/lib/pastel/decorator_chain.rb
pastel-0.7.3 lib/pastel/decorator_chain.rb
pastel-0.7.2 lib/pastel/decorator_chain.rb
pastel-0.7.1 lib/pastel/decorator_chain.rb