Class: Statemachine::Generate::SrcBuilder
- Inherits:
-
Object
- Object
- Statemachine::Generate::SrcBuilder
- Defined in:
- lib/statemachine/generate/src_builder.rb
Instance Method Summary collapse
- #<<(content) ⇒ Object
- #add_indents ⇒ Object
- #indent! ⇒ Object
-
#initialize ⇒ SrcBuilder
constructor
A new instance of SrcBuilder.
- #newline! ⇒ Object
- #to_s ⇒ Object
- #undent! ⇒ Object
Constructor Details
#initialize ⇒ SrcBuilder
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_indents ⇒ Object
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_s ⇒ Object
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 |