Class: Handsoap::CodeWriter
- Inherits:
-
Object
- Object
- Handsoap::CodeWriter
- Defined in:
- lib/handsoap/compiler.rb
Instance Method Summary collapse
- #begin(text) ⇒ Object
- #end(str = "end") ⇒ Object
- #indent ⇒ Object
-
#initialize ⇒ CodeWriter
constructor
A new instance of CodeWriter.
- #puts(text = "") ⇒ Object
- #to_s ⇒ Object
- #unindent ⇒ Object
Constructor Details
#initialize ⇒ CodeWriter
Returns a new instance of CodeWriter.
5 6 7 8 |
# File 'lib/handsoap/compiler.rb', line 5 def initialize @buffer = "" @indentation = 0 end |
Instance Method Details
#begin(text) ⇒ Object
10 11 12 13 |
# File 'lib/handsoap/compiler.rb', line 10 def begin(text) puts(text) indent end |
#end(str = "end") ⇒ Object
15 16 17 18 |
# File 'lib/handsoap/compiler.rb', line 15 def end(str = "end") unindent puts(str) end |
#indent ⇒ Object
25 26 27 |
# File 'lib/handsoap/compiler.rb', line 25 def indent @indentation = @indentation + 1 end |
#puts(text = "") ⇒ Object
20 21 22 23 |
# File 'lib/handsoap/compiler.rb', line 20 def puts(text = "") @buffer << text.gsub(/^(.*)$/, (" " * @indentation) + "\\1") @buffer << "\n" # unless @buffer.match(/\n$/) end |
#to_s ⇒ Object
33 34 35 |
# File 'lib/handsoap/compiler.rb', line 33 def to_s @buffer end |
#unindent ⇒ Object
29 30 31 |
# File 'lib/handsoap/compiler.rb', line 29 def unindent @indentation = @indentation - 1 end |