Class: Teapot::Indentation
- Inherits:
-
Object
- Object
- Teapot::Indentation
- Defined in:
- lib/teapot/substitutions.rb
Constant Summary collapse
- TAB =
"\t".freeze
Class Method Summary collapse
Instance Method Summary collapse
- #+(other) ⇒ Object
- #<<(text) ⇒ Object
- #by(depth) ⇒ Object
- #freeze ⇒ Object
- #indentation ⇒ Object
-
#initialize(prefix, level, indent) ⇒ Indentation
constructor
A new instance of Indentation.
- #with_prefix(prefix) ⇒ Object
Constructor Details
#initialize(prefix, level, indent) ⇒ Indentation
Returns a new instance of Indentation.
25 26 27 28 29 |
# File 'lib/teapot/substitutions.rb', line 25 def initialize(prefix, level, indent) @prefix = prefix @level = level @indent = indent end |
Class Method Details
.none ⇒ Object
61 62 63 |
# File 'lib/teapot/substitutions.rb', line 61 def self.none self.new('', 0, TAB) end |
Instance Method Details
#+(other) ⇒ Object
45 46 47 |
# File 'lib/teapot/substitutions.rb', line 45 def + other indentation + other end |
#<<(text) ⇒ Object
49 50 51 |
# File 'lib/teapot/substitutions.rb', line 49 def << text text.gsub(/^/){|m| m + indentation} end |
#by(depth) ⇒ Object
53 54 55 |
# File 'lib/teapot/substitutions.rb', line 53 def by(depth) Indentation.new(@prefix, @level + depth, @indent) end |
#freeze ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/teapot/substitutions.rb', line 31 def freeze indentation @prefix.freeze @level.freeze @indent.freeze super end |
#indentation ⇒ Object
41 42 43 |
# File 'lib/teapot/substitutions.rb', line 41 def indentation @indentation ||= @prefix + (@indent * @level) end |
#with_prefix(prefix) ⇒ Object
57 58 59 |
# File 'lib/teapot/substitutions.rb', line 57 def with_prefix(prefix) Indentation.new(prefix, @level, @indent) end |