Class: Unparser::Buffer

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

Overview

Buffer used to emit into

ignore :reek:TooManyMethods

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



18
19
20
21
# File 'lib/unparser/buffer.rb', line 18

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)


31
32
33
34
35
36
37
# File 'lib/unparser/buffer.rb', line 31

def append(string)
  if @content[-1].eql?(NL)
    prefix
  end
  write(string)
  self
end

#append_without_prefix(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 a string without an indentation prefix

Parameters:

  • string (String)

Returns:

  • (self)


47
48
49
50
# File 'lib/unparser/buffer.rb', line 47

def append_without_prefix(string)
  write(string)
  self
end

#capture_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.

Capture the content written to the buffer within the block

Returns:

  • (String)


111
112
113
114
115
# File 'lib/unparser/buffer.rb', line 111

def capture_content
  size_before = @content.size
  yield
  @content[size_before..-1]
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)


101
102
103
# File 'lib/unparser/buffer.rb', line 101

def content
  @content.dup.freeze
end

#fresh_line?Boolean

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.

Test for a fresh line

Returns:

  • (Boolean)


91
92
93
# File 'lib/unparser/buffer.rb', line 91

def fresh_line?
  @content.empty? || @content[-1].eql?(NL)
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)


58
59
60
61
# File 'lib/unparser/buffer.rb', line 58

def indent
  @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)


80
81
82
83
# File 'lib/unparser/buffer.rb', line 80

def nl
  write(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)


69
70
71
72
# File 'lib/unparser/buffer.rb', line 69

def unindent
  @indent -= 1
  self
end