Class: AQL::Buffer
- Inherits:
-
Object
- Object
- AQL::Buffer
- Defined in:
- lib/aql/buffer.rb
Overview
The emit buffer
Class Method Summary collapse
-
.utf8_encode(string) ⇒ String
private
Encode string in UTF-8.
Instance Method Summary collapse
-
#append(content) ⇒ self
private
Append content to buffer.
-
#binary(left, operator, right) ⇒ self
private
Emit binary.
-
#content ⇒ String
private
Return content.
-
#delimited(nodes, delimiter = ', ') ⇒ self
private
Emit delimited nodes.
-
#initialize ⇒ undefined
constructor
private
Initialize object.
-
#parentheses(open = '(', close = ')') ⇒ self
private
Emit block in parentheses.
-
#wrap_delimited(open, nodes, close) ⇒ self
private
Emit wrapped delimited.
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
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
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
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
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 |
#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
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
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
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
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 |