Class: AQL::Buffer

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

Overview

The emit buffer

Class Method Summary collapse

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



12
13
14
# File 'lib/aql/buffer.rb', line 12

def initialize
  @buffer = []
end

Class Method Details

.utf8_encode(string) ⇒ 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.

Encode string in UTF-8

Parameters:

  • string (String)

Returns:

  • (String)


111
112
113
# File 'lib/aql/buffer.rb', line 111

def self.utf8_encode(string)
  string.encode(Encoding::UTF_8)
end

Instance Method Details

#append(content) ⇒ 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 content to buffer

Parameters:

  • content (String)

Returns:

  • (self)


87
88
89
90
# File 'lib/aql/buffer.rb', line 87

def append(content)
  @buffer << self.class.utf8_encode(content)
  self
end

#binary(left, operator, right) ⇒ 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.

Emit binary

Parameters:

  • left (Node)
  • operator (Symbol)
  • right (Node)

Returns:

  • (self)


71
72
73
74
75
76
77
# File 'lib/aql/buffer.rb', line 71

def binary(left, operator, right)
  parentheses do
    left.visit(self)
    append(" #{operator} ")
    right.visit(self)
  end
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

Returns:

  • (String)


98
99
100
# File 'lib/aql/buffer.rb', line 98

def content
  @buffer.join.freeze
end

#delimited(nodes, delimiter = ', ') ⇒ 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.

Emit delimited nodes

Parameters:

  • nodes (Enumerable<Node>)

Returns:

  • (self)


52
53
54
55
56
57
58
59
# File 'lib/aql/buffer.rb', line 52

def delimited(nodes, delimiter = ', ')
  max = nodes.length - 1
  nodes.each_with_index do |element, index|
    element.visit(self)
    append(delimiter) if index < max
  end
  self
end

#parentheses(open = '(', close = ')') ⇒ 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.

Emit block in parentheses

Returns:

  • (self)


38
39
40
41
42
# File 'lib/aql/buffer.rb', line 38

def parentheses(open = '(', close = ')')
  append(open)
  yield
  append(close)
end

#wrap_delimited(open, nodes, close) ⇒ 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.

Emit wrapped delimited

Parameters:

  • open (String)
  • nodes (Enumerable<Node>)
  • close (String)

Returns:

  • (self)


26
27
28
29
30
# File 'lib/aql/buffer.rb', line 26

def wrap_delimited(open, nodes, close)
  parentheses(open, close) do
    delimited(nodes)
  end
end