Class: PrettyPrint::GroupQueue
- Inherits:
-
Object
- Object
- PrettyPrint::GroupQueue
- 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.
Instance Method Summary collapse
-
#delete(group) ⇒ Object
Remote
group
from this queue. -
#deq ⇒ Object
Returns the outer group of the queue.
-
#enq(group) ⇒ Object
Enqueue
group
. -
#initialize(*groups) ⇒ GroupQueue
constructor
Create a GroupQueue object.
Constructor Details
#initialize(*groups) ⇒ GroupQueue
Create a GroupQueue object
Arguments:
-
groups
- one or more PrettyPrint::Group objects
465 466 467 468 |
# File 'lib/prettyprint.rb', line 465 def initialize(*groups) @queue = [] groups.each {|g| enq g} end |
Instance Method Details
#delete(group) ⇒ Object
Remote group
from this queue
497 498 499 |
# File 'lib/prettyprint.rb', line 497 def delete(group) @queue[group.depth].delete(group) end |
#deq ⇒ Object
Returns the outer group of the queue
481 482 483 484 485 486 487 488 489 490 491 492 493 494 |
# File 'lib/prettyprint.rb', line 481 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) ⇒ Object
Enqueue 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
474 475 476 477 478 |
# File 'lib/prettyprint.rb', line 474 def enq(group) depth = group.depth @queue << [] until depth < @queue.length @queue[depth] << group end |