Class: Unparser::Buffer
- Inherits:
-
Object
- Object
- Unparser::Buffer
- Defined in:
- lib/unparser/buffer.rb
Overview
Buffer used to emit into
Constant Summary collapse
- NL =
"\n".freeze
Instance Method Summary collapse
-
#append(string) ⇒ self
private
Append string.
-
#content ⇒ String
private
Return content of buffer.
-
#indent ⇒ self
private
Increase indent.
-
#initialize ⇒ undefined
constructor
private
Initialize object.
-
#nl ⇒ self
private
Write newline.
-
#unindent ⇒ self
private
Decrease indent.
Constructor Details
#initialize ⇒ undefined
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize object
14 15 16 17 |
# File 'lib/unparser/buffer.rb', line 14 def initialize @content = '' @indent = 0 end |
Instance Method Details
#append(string) ⇒ self
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Append string
27 28 29 30 31 32 33 |
# File 'lib/unparser/buffer.rb', line 27 def append(string) if @content[-1] == NL prefix end @content << string self end |
#content ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return content of buffer
76 77 78 |
# File 'lib/unparser/buffer.rb', line 76 def content @content.dup.freeze end |
#indent ⇒ self
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Increase indent
41 42 43 44 45 |
# File 'lib/unparser/buffer.rb', line 41 def indent nl @indent+=1 self end |
#nl ⇒ self
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Write newline
65 66 67 68 |
# File 'lib/unparser/buffer.rb', line 65 def nl @content << NL self end |
#unindent ⇒ self
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Decrease indent
53 54 55 56 57 |
# File 'lib/unparser/buffer.rb', line 53 def unindent nl @indent-=1 self end |