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 15
def self.empty
  @empty ||= self.new
end
new(decorators = [].freeze) click to toggle source

Create a decorator chain

@api public

# File lib/pastel/decorator_chain.rb, line 22
def initialize(decorators = [].freeze)
  @decorators = decorators
end

Public Instance Methods

==(other) click to toggle source

Compare colors for equivalence of attributes

@return [Boolean]

@api public

# File lib/pastel/decorator_chain.rb, line 60
def ==(other)
  other.is_a?(self.class) && decorators == other.decorators
end
add(decorator) click to toggle source

Add decorator

@param [String] decorator

@api public

# File lib/pastel/decorator_chain.rb, line 31
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 42
def each(&block)
  decorators.each(&block)
end
eql?(other) click to toggle source

Compare colors for equality of attributes

@return [Boolean]

@api public

# File lib/pastel/decorator_chain.rb, line 51
def eql?(other)
  instance_of?(other.class) && decorators.eql?(other.decorators)
end
hash() click to toggle source

Hash for this instance and its attributes

@return [Numeric]

@api public

# File lib/pastel/decorator_chain.rb, line 78
def hash
  [self.class, decorators].hash
end
inspect() click to toggle source

Inspect this instance attributes

@return [String]

@api public

# File lib/pastel/decorator_chain.rb, line 69
def inspect
  "#<#{self.class.name} decorators=#{decorators.inspect}>"
end