Sha256: fef83b554d66c834887fd50a1ecf3992c59fc24e0fc63ac58ea8ccaccaf514ef

Contents?: true

Size: 716 Bytes

Versions: 7

Compression:

Stored size: 716 Bytes

Contents

# coding: utf-8

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)
      self.class.new(decorators + [decorator])
    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

7 entries across 7 versions & 1 rubygems

Version Path
pastel-0.6.1 lib/pastel/decorator_chain.rb
pastel-0.6.0 lib/pastel/decorator_chain.rb
pastel-0.5.3 lib/pastel/decorator_chain.rb
pastel-0.5.2 lib/pastel/decorator_chain.rb
pastel-0.5.1 lib/pastel/decorator_chain.rb
pastel-0.5.0 lib/pastel/decorator_chain.rb
pastel-0.4.0 lib/pastel/decorator_chain.rb