Class: Pastel::DecoratorChain Private

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/pastel/decorator_chain.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Collects a list of decorators for styling a string

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(decorators = [].freeze) ⇒ DecoratorChain

Create a decorator chain



22
23
24
# File 'lib/pastel/decorator_chain.rb', line 22

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

Class Method Details

.emptyDecoratorChain

Create an empty decorator chain

Returns:



15
16
17
# File 'lib/pastel/decorator_chain.rb', line 15

def self.empty
  @empty ||= self.new
end

Instance Method Details

#==(other) ⇒ Boolean

Compare colors for equivalence of attributes

Returns:

  • (Boolean)


60
61
62
# File 'lib/pastel/decorator_chain.rb', line 60

def ==(other)
  other.is_a?(self.class) && decorators == other.decorators
end

#add(decorator) ⇒ Object

Add decorator

Parameters:

  • decorator (String)


31
32
33
34
35
36
37
# 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) ⇒ Object

Iterate over list of decorators



42
43
44
# File 'lib/pastel/decorator_chain.rb', line 42

def each(&block)
  decorators.each(&block)
end

#eql?(other) ⇒ Boolean

Compare colors for equality of attributes

Returns:

  • (Boolean)


51
52
53
# File 'lib/pastel/decorator_chain.rb', line 51

def eql?(other)
  instance_of?(other.class) && decorators.eql?(other.decorators)
end

#hashNumeric

Hash for this instance and its attributes

Returns:

  • (Numeric)


78
79
80
# File 'lib/pastel/decorator_chain.rb', line 78

def hash
  [self.class, decorators].hash
end

#inspectString

Inspect this instance attributes

Returns:

  • (String)


69
70
71
# File 'lib/pastel/decorator_chain.rb', line 69

def inspect
  "#<#{self.class.name} decorators=#{decorators.inspect}>"
end