Class: Handsoap::CodeWriter

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

Overview

Used internally to generate Ruby source code

Instance Method Summary collapse

Constructor Details

#initializeCodeWriter

:nodoc: all



6
7
8
9
# File 'lib/handsoap/compiler.rb', line 6

def initialize
  @buffer = ""
  @indentation = 0
end

Instance Method Details

#begin(text) ⇒ Object



11
12
13
14
# File 'lib/handsoap/compiler.rb', line 11

def begin(text)
  puts(text)
  indent
end

#end(str = "end") ⇒ Object



16
17
18
19
# File 'lib/handsoap/compiler.rb', line 16

def end(str = "end")
  unindent
  puts(str)
end

#indentObject



26
27
28
# File 'lib/handsoap/compiler.rb', line 26

def indent
  @indentation = @indentation + 1
end

#puts(text = "") ⇒ Object



21
22
23
24
# File 'lib/handsoap/compiler.rb', line 21

def puts(text = "")
  @buffer << text.gsub(/^(.*)$/, ("  " * @indentation) + "\\1")
  @buffer << "\n" # unless @buffer.match(/\n$/)
end

#to_sObject



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

def to_s
  @buffer
end

#unindentObject



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

def unindent
  @indentation = @indentation - 1
end