Sha256: c2194d19db556c3d474d9b21528fdfd856b53804916a4a107a4f9e6465cd229b

Contents?: true

Size: 701 Bytes

Versions: 4

Compression:

Stored size: 701 Bytes

Contents

# coding: utf-8

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

    attr_reader :decorators

    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
  end # DecoratorChain
end # Patel

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pastel-0.3.0 lib/pastel/decorator_chain.rb
pastel-0.2.1 lib/pastel/decorator_chain.rb
pastel-0.2.0 lib/pastel/decorator_chain.rb
pastel-0.1.0 lib/pastel/decorator_chain.rb