class Pastel::DecoratorChain

Collects a list of decorators for styling a string

@api private

Attributes

decorators[R]

Public Class Methods

empty() click to toggle source

Create an empty decorator chain

@return [DecoratorChain]

@api public

# File lib/pastel/decorator_chain.rb, line 39
def self.empty
  new([])
end
new(decorators = []) click to toggle source
# File lib/pastel/decorator_chain.rb, line 12
def initialize(decorators = [])
  @decorators = decorators
end

Public Instance Methods

add(decorator) click to toggle source

Add decorator

@api public

# File lib/pastel/decorator_chain.rb, line 19
def add(decorator)
  if decorators.include?(decorator)
    self.class.new(decorators)
  else
    self.class.new(decorators + [decorator])
  end
end
each(&block) click to toggle source

Iterate over list of decorators

@api public

# File lib/pastel/decorator_chain.rb, line 30
def each(&block)
  decorators.each(&block)
end