Class: Teapot::Indentation
- Inherits:
-
Object
- Object
- Teapot::Indentation
- Defined in:
- lib/teapot/substitutions.rb
Class Method Summary collapse
Instance Method Summary collapse
- #+(other) ⇒ Object
- #<<(text) ⇒ Object
- #by(depth) ⇒ 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.
23 24 25 26 27 |
# File 'lib/teapot/substitutions.rb', line 23 def initialize(prefix, level, indent) @prefix = prefix @level = level @indent = indent end |
Class Method Details
.none ⇒ Object
49 50 51 |
# File 'lib/teapot/substitutions.rb', line 49 def self.none self.new('', 0, "\t") end |
Instance Method Details
#+(other) ⇒ Object
33 34 35 |
# File 'lib/teapot/substitutions.rb', line 33 def + other indentation + other end |
#<<(text) ⇒ Object
37 38 39 |
# File 'lib/teapot/substitutions.rb', line 37 def << text text.gsub(/^/){|m| m + indentation} end |
#by(depth) ⇒ Object
41 42 43 |
# File 'lib/teapot/substitutions.rb', line 41 def by(depth) Indentation.new(@prefix, @level + depth, @indent) end |
#indentation ⇒ Object
29 30 31 |
# File 'lib/teapot/substitutions.rb', line 29 def indentation @indentation ||= @prefix + (@indent * @level) end |
#with_prefix(prefix) ⇒ Object
45 46 47 |
# File 'lib/teapot/substitutions.rb', line 45 def with_prefix(prefix) Indentation.new(prefix, @level, @indent) end |