Class: Unparser::Buffer

Inherits:
Object
  • Object
show all
Defined in:
lib/unparser/buffer.rb

Overview

Buffer used to emit into

Constant Summary collapse

NL =
"\n".freeze

Instance Method Summary collapse

Constructor Details

#initializeundefined

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

Parameters:

  • string (String)

Returns:

  • (self)


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

#contentString

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

Returns:

  • (String)


76
77
78
# File 'lib/unparser/buffer.rb', line 76

def content
  @content.dup.freeze
end

#indentself

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

Returns:

  • (self)


41
42
43
44
45
# File 'lib/unparser/buffer.rb', line 41

def indent
  nl
  @indent+=1
  self
end

#nlself

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

Returns:

  • (self)


65
66
67
68
# File 'lib/unparser/buffer.rb', line 65

def nl
  @content << NL
  self
end

#unindentself

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

Returns:

  • (self)


53
54
55
56
57
# File 'lib/unparser/buffer.rb', line 53

def unindent
  nl
  @indent-=1
  self
end