Sha256: 9c7ae7eeef607ec877aa2ec9a61ae3a902b194a375e98aba235c1e296d9d4934
Contents?: true
Size: 1.86 KB
Versions: 1
Compression:
Stored size: 1.86 KB
Contents
module Unparser # Buffer used to emit into class Buffer NL = "\n".freeze # Initialize object # # @return [undefined] # # @api private # def initialize @content = '' @indent = 0 end # Append string # # @param [String] string # # @return [self] # # @api private # def append(string) if @content[-1] == NL prefix end @content << string self end # Append a string without an indentation prefix # # @param [String] string # # @return [self] # # @api private # def append_without_prefix(string) @content << string self end # Increase indent # # @return [self] # # @api private # def indent @indent+=1 self end # Decrease indent # # @return [self] # # @api private # def unindent @indent-=1 self end # Write newline # # @return [self] # # @api private # def nl @content << NL self end # Test for a fresh line # # @return [true] # if the buffer content ends with a fresh line # # @return [false] # otherwise # # @api private # def fresh_line? @content.empty? || @content[-1] == NL end # Return content of buffer # # @return [String] # # @api private # def content @content.dup.freeze end # Capture the content written to the buffer within the block # # @return [String] # # @api private # def capture_content size_before = @content.size yield @content[size_before..-1] end private # Write prefix # # @return [String] # # @api private # def prefix @content << ' '*@indent end end # Buffer end # Unparser
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
unparser-0.1.3 | lib/unparser/buffer.rb |