123456789_123456789_123456789_123456789_123456789_

Class: PrettyPrint::GroupQueue

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

Overview

The GroupQueue class is used for managing the queue of Group to be pretty printed.

This queue groups the Group objects, based on their depth.

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

Class Method Summary

Instance Method Summary

Constructor Details

.new(*groups) ⇒ GroupQueue

Create a GroupQueue object

Arguments:

  • groups - one or more Group objects

[ GitHub ]

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

def initialize(*groups)
  @queue = []
  groups.each {|g| enq g}
end

Instance Method Details

#delete(group)

Remote PrettyPrint#group from this queue

[ GitHub ]

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

def delete(group)
  @queue[group.depth].delete(group)
end

#deq

Returns the outer group of the queue

[ GitHub ]

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

def deq
  @queue.each {|gs|
    (gs.length-1).downto(0) {|i|
      unless gs[i].breakables.empty?
        group = gs.slice!(i, 1).first
        group.break
        return group
      end
    }
    gs.each {|group| group.break}
    gs.clear
  }
  return nil
end

#enq(group)

Enqueue PrettyPrint#group

This does not strictly append the group to the end of the queue, but instead adds it in line, base on the group.depth

[ GitHub ]

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

def enq(group)
  depth = group.depth
  @queue << [] until depth < @queue.length
  @queue[depth] << group
end