Class: Statemachine::Generate::SrcBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/statemachine/generate/src_builder.rb

Instance Method Summary collapse

Constructor Details

#initializeSrcBuilder

Returns a new instance of SrcBuilder.



5
6
7
8
9
10
# File 'lib/statemachine/generate/src_builder.rb', line 5

def initialize
  @src = ""
  @is_newline = true
  @indents = 0
  @indent_size = 2
end

Instance Method Details

#<<(content) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/statemachine/generate/src_builder.rb', line 12

def <<(content)
  if content == :endl
    newline!
  else
    add_indents if @is_newline
    @src += content.to_s
  end
  return self
end

#add_indentsObject



41
42
43
44
# File 'lib/statemachine/generate/src_builder.rb', line 41

def add_indents
  @src += (" " * (@indent_size * @indents)) 
  @is_newline = false
end

#indent!Object



31
32
33
34
# File 'lib/statemachine/generate/src_builder.rb', line 31

def indent!
  @indents += 1
  return self
end

#newline!Object



22
23
24
25
# File 'lib/statemachine/generate/src_builder.rb', line 22

def newline!
  @src += "\n"
  @is_newline = true
end

#to_sObject



27
28
29
# File 'lib/statemachine/generate/src_builder.rb', line 27

def to_s
  return @src
end

#undent!Object



36
37
38
39
# File 'lib/statemachine/generate/src_builder.rb', line 36

def undent!
  @indents -= 1
  return self
end