123456789_123456789_123456789_123456789_123456789_

Class: PrettyPrint::Text

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: lib/prettyprint.rb

Overview

The Text class is the means by which to collect strings from objects.

This class is intended for internal use of the ::PrettyPrint buffers.

Class Method Summary

Instance Attribute Summary

  • #width readonly

    The total width of the objects included in this Text object.

Instance Method Summary

Constructor Details

.newText

Creates a new text object.

This constructor takes no arguments.

The workflow is to append a Text object to the buffer, and being able to call the buffer.last() to reference it.

As there are objects, use #add to include the objects and the width to utilized by the String version of this object.

[ GitHub ]

  
# File 'lib/prettyprint.rb', line 312

def initialize
  @objs = []
  @width = 0
end

Instance Attribute Details

#width (readonly)

The total width of the objects included in this Text object.

[ GitHub ]

  
# File 'lib/prettyprint.rb', line 318

attr_reader :width

Instance Method Details

#add(obj, width)

Include obj in the objects to be pretty printed, and increment this Text object’s total width by #width

[ GitHub ]

  
# File 'lib/prettyprint.rb', line 330

def add(obj, width)
  @objs << obj
  @width += width
end

#output(out, output_width)

Render the String text of the objects that have been added to this Text object.

Output the text to out, and increment the width to output_width

[ GitHub ]

  
# File 'lib/prettyprint.rb', line 323

def output(out, output_width)
  @objs.each {|obj| out << obj}
  output_width + @width
end