Class: Pastel::DecoratorChain Private
- Inherits:
-
Object
- Object
- Pastel::DecoratorChain
- 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
-
.empty ⇒ DecoratorChain
Create an empty decorator chain.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compare colors for equivalence of attributes.
-
#add(decorator) ⇒ Object
Add decorator.
-
#each(&block) ⇒ Object
Iterate over list of decorators.
-
#eql?(other) ⇒ Boolean
Compare colors for equality of attributes.
-
#hash ⇒ Numeric
Hash for this instance and its attributes.
-
#initialize(decorators = [].freeze) ⇒ DecoratorChain
constructor
Create a decorator chain.
-
#inspect ⇒ String
Inspect this instance attributes.
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
.empty ⇒ DecoratorChain
Create an empty decorator chain
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
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
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
51 52 53 |
# File 'lib/pastel/decorator_chain.rb', line 51 def eql?(other) instance_of?(other.class) && decorators.eql?(other.decorators) end |
#hash ⇒ Numeric
Hash for this instance and its attributes
78 79 80 |
# File 'lib/pastel/decorator_chain.rb', line 78 def hash [self.class, decorators].hash end |
#inspect ⇒ String
Inspect this instance attributes
69 70 71 |
# File 'lib/pastel/decorator_chain.rb', line 69 def inspect "#<#{self.class.name} decorators=#{decorators.inspect}>" end |