Class: Handsoap::CodeWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/handsoap/compiler.rb

Instance Method Summary collapse

Constructor Details

#initializeCodeWriter

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

#indentObject



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_sObject



33
34
35
# File 'lib/handsoap/compiler.rb', line 33

def to_s
  @buffer
end

#unindentObject



29
30
31
# File 'lib/handsoap/compiler.rb', line 29

def unindent
  @indentation = @indentation - 1
end