Class: XCRes::StringBuilder
- Inherits:
-
Object
- Object
- XCRes::StringBuilder
- Defined in:
- lib/xcres/builder/string_builder.rb
Instance Attribute Summary collapse
-
#indentation_string ⇒ Object
Returns the value of attribute indentation_string.
-
#result ⇒ Object
Returns the value of attribute result.
Instance Method Summary collapse
- #<<(input) ⇒ Object (also: #write)
-
#initialize ⇒ StringBuilder
constructor
A new instance of StringBuilder.
- #section(&block) ⇒ Object
- #writeln(input = '') ⇒ Object
Constructor Details
#initialize ⇒ StringBuilder
Returns a new instance of StringBuilder.
6 7 8 9 |
# File 'lib/xcres/builder/string_builder.rb', line 6 def initialize self.indentation_string = ' ' self.result = '' end |
Instance Attribute Details
#indentation_string ⇒ Object
Returns the value of attribute indentation_string.
3 4 5 |
# File 'lib/xcres/builder/string_builder.rb', line 3 def indentation_string @indentation_string end |
#result ⇒ Object
Returns the value of attribute result.
4 5 6 |
# File 'lib/xcres/builder/string_builder.rb', line 4 def result @result end |
Instance Method Details
#<<(input) ⇒ Object Also known as: write
11 12 13 14 15 16 |
# File 'lib/xcres/builder/string_builder.rb', line 11 def << input # Only indent string inputs on nested / delegating string builders input = self.indentation_string + input unless result.is_a? String self.result << input end |
#section(&block) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/xcres/builder/string_builder.rb', line 24 def section &block builder = self.class.new builder.indentation_string = self.indentation_string builder.result = self block.call builder end |
#writeln(input = '') ⇒ Object
20 21 22 |
# File 'lib/xcres/builder/string_builder.rb', line 20 def writeln input='' self << input + "\n" end |