Sha256: fe4b48940dc51488c6769658d8531dfdc739586197cd4f27b5bcb442fac8fe1d

Contents?: true

Size: 602 Bytes

Versions: 8

Compression:

Stored size: 602 Bytes

Contents

class XCRes::StringBuilder

  attr_accessor :indentation_string
  attr_accessor :result

  def initialize
    self.indentation_string = '    '
    self.result = ''
  end

  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

  alias write :<<

  def writeln input=''
    self << input + "\n"
  end

  def section &block
    builder = self.class.new
    builder.indentation_string = self.indentation_string
    builder.result = self
    block.call builder
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
xcres-0.6.1 lib/xcres/builder/string_builder.rb
xcres-0.6.0 lib/xcres/builder/string_builder.rb
xcres-0.5.0 lib/xcres/builder/string_builder.rb
xcres-0.4.4 lib/xcres/builder/string_builder.rb
xcres-0.4.3 lib/xcres/builder/string_builder.rb
xcres-0.4.2 lib/xcres/builder/string_builder.rb
xcres-0.4.1 lib/xcres/builder/string_builder.rb
xcres-0.4.0 lib/xcres/builder/string_builder.rb