Class: PrettyPrint::GroupQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/prettyprint.rb

Instance Method Summary collapse

Constructor Details

#initialize(*groups) ⇒ GroupQueue

Returns a new instance of GroupQueue.



329
330
331
332
# File 'lib/prettyprint.rb', line 329

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

Instance Method Details

#delete(group) ⇒ Object



355
356
357
# File 'lib/prettyprint.rb', line 355

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

#deqObject



340
341
342
343
344
345
346
347
348
349
350
351
352
353
# File 'lib/prettyprint.rb', line 340

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



334
335
336
337
338
# File 'lib/prettyprint.rb', line 334

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