123456789_123456789_123456789_123456789_123456789_

Class: PrettyPrint::Breakable

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

Overview

The Breakable class is used for breaking up object information

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

Class Method Summary

Instance Attribute Summary

  • #indent readonly

    The number of spaces to indent.

  • #obj readonly

    Holds the separator String.

  • #width readonly

    The width of #obj / sep

Instance Method Summary

Constructor Details

.new(sep, width, q) ⇒ Breakable

Create a new Breakable object.

Arguments:

  • sep String of the separator

  • #width Integer width of the sep

  • q parent ::PrettyPrint object, to base from

[ GitHub ]

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

def initialize(sep, width, q)
  @obj = sep
  @width = width
  @pp = q
  @indent = q.indent
  @group = q.current_group
  @group.breakables.push self
end

Instance Attribute Details

#indent (readonly)

The number of spaces to indent.

This is inferred from q within ::PrettyPrint, passed in .new

[ GitHub ]

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

attr_reader :indent

#obj (readonly)

Holds the separator String

The sep argument from .new

[ GitHub ]

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

attr_reader :obj

#width (readonly)

The width of #obj / sep

[ GitHub ]

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

attr_reader :width

Instance Method Details

#output(out, output_width)

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

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

[ GitHub ]

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

def output(out, output_width)
  @group.breakables.shift
  if @group.break?
    out << @pp.newline
    out << @pp.genspace.call(@indent)
    @indent
  else
    @pp.group_queue.delete @group if @group.breakables.empty?
    out << @obj
    output_width + @width
  end
end