Class: RubyUIConverter::CodeBuilder
- Inherits:
-
Object
- Object
- RubyUIConverter::CodeBuilder
- Defined in:
- lib/ruby_ui_converter/code_builder.rb
Overview
Accumulates indented lines of Ruby source.
Instance Attribute Summary collapse
-
#level ⇒ Object
readonly
Returns the value of attribute level.
Instance Method Summary collapse
- #dedent ⇒ Object
- #indent ⇒ Object
-
#initialize(indent: " ", level: 0) ⇒ CodeBuilder
constructor
A new instance of CodeBuilder.
- #line(str = nil) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(indent: " ", level: 0) ⇒ CodeBuilder
Returns a new instance of CodeBuilder.
6 7 8 9 10 |
# File 'lib/ruby_ui_converter/code_builder.rb', line 6 def initialize(indent: " ", level: 0) @indent = indent @level = level @lines = [] end |
Instance Attribute Details
#level ⇒ Object (readonly)
Returns the value of attribute level.
12 13 14 |
# File 'lib/ruby_ui_converter/code_builder.rb', line 12 def level @level end |
Instance Method Details
#dedent ⇒ Object
24 25 26 27 |
# File 'lib/ruby_ui_converter/code_builder.rb', line 24 def dedent @level -= 1 if @level.positive? self end |
#indent ⇒ Object
19 20 21 22 |
# File 'lib/ruby_ui_converter/code_builder.rb', line 19 def indent @level += 1 self end |
#line(str = nil) ⇒ Object
14 15 16 17 |
# File 'lib/ruby_ui_converter/code_builder.rb', line 14 def line(str = nil) @lines << (str.nil? || str.empty? ? "" : (@indent * @level) + str) self end |
#to_s ⇒ Object
29 30 31 |
# File 'lib/ruby_ui_converter/code_builder.rb', line 29 def to_s "#{@lines.join("\n")}\n" end |