Class: XcodeResultBundleProcessor::IndentedStringBuffer
- Inherits:
-
Object
- Object
- XcodeResultBundleProcessor::IndentedStringBuffer
- Defined in:
- lib/xcoderesultbundleprocessor/indented_string_buffer.rb
Instance Method Summary collapse
- #<<(arg) ⇒ Object
- #add_newline ⇒ Object
- #indent ⇒ Object
-
#initialize(buffer = nil, indent_level = 0) ⇒ IndentedStringBuffer
constructor
A new instance of IndentedStringBuffer.
- #to_s ⇒ Object
Constructor Details
#initialize(buffer = nil, indent_level = 0) ⇒ IndentedStringBuffer
Returns a new instance of IndentedStringBuffer.
3 4 5 6 7 |
# File 'lib/xcoderesultbundleprocessor/indented_string_buffer.rb', line 3 def initialize(buffer=nil, indent_level=0) @buffer = buffer || '' @indent_spaces = 2 @indent_level = indent_level end |
Instance Method Details
#<<(arg) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/xcoderesultbundleprocessor/indented_string_buffer.rb', line 9 def <<(arg) Array(arg).each do |line| @buffer << ' ' * (@indent_spaces * @indent_level) << line @buffer << "\n" unless line.end_with?("\n") @buffer end self end |
#add_newline ⇒ Object
18 19 20 21 |
# File 'lib/xcoderesultbundleprocessor/indented_string_buffer.rb', line 18 def add_newline @buffer << "\n" self end |
#indent ⇒ Object
23 24 25 |
# File 'lib/xcoderesultbundleprocessor/indented_string_buffer.rb', line 23 def indent IndentedStringBuffer.new(@buffer, @indent_level + 1) end |
#to_s ⇒ Object
27 28 29 30 |
# File 'lib/xcoderesultbundleprocessor/indented_string_buffer.rb', line 27 def to_s return "\n" if @buffer.empty? @buffer end |