Class: SuperDiff::Core::TieredLinesElider::BuildBoxes

Inherits:
Object
  • Object
show all
Defined in:
lib/super_diff/core/tiered_lines_elider.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lines) ⇒ BuildBoxes

Returns a new instance of BuildBoxes.



374
375
376
377
378
379
# File 'lib/super_diff/core/tiered_lines_elider.rb', line 374

def initialize(lines)
  @lines = lines

  @open_collection_boxes = []
  @final_boxes = []
end

Instance Attribute Details

#final_boxesObject (readonly)

Returns the value of attribute final_boxes.



372
373
374
# File 'lib/super_diff/core/tiered_lines_elider.rb', line 372

def final_boxes
  @final_boxes
end

Class Method Details

.call(lines) ⇒ Object



366
367
368
369
370
# File 'lib/super_diff/core/tiered_lines_elider.rb', line 366

def self.call(lines)
  builder = new(lines)
  builder.build
  builder.final_boxes
end

Instance Method Details

#buildObject



381
382
383
384
385
386
387
388
389
390
391
392
393
# File 'lib/super_diff/core/tiered_lines_elider.rb', line 381

def build
  lines.each_with_index do |line, index|
    if line.opens_collection?
      open_new_collection_box(line, index)
    elsif line.closes_collection?
      extend_working_collection_box(index)
      close_working_collection_box
    else
      extend_working_collection_box(index) if open_collection_boxes.any?
      record_item_box(line, index)
    end
  end
end