Class: Marvi::Diagram::SequenceRenderer

Inherits:
Object
  • Object
show all
Includes:
BoxDrawing
Defined in:
lib/marvi/diagram.rb

Overview

Renders ‘sequenceDiagram` participants, lifelines and messages.

Constant Summary collapse

PARTICIPANT_GAP =
4

Constants included from BoxDrawing

BoxDrawing::BOX_HEIGHT

Instance Method Summary collapse

Methods included from BoxDrawing

#box_width, #draw_box

Constructor Details

#initialize(lines, max_width) ⇒ SequenceRenderer

Returns a new instance of SequenceRenderer.



362
363
364
365
366
367
# File 'lib/marvi/diagram.rb', line 362

def initialize(lines, max_width)
  @lines = lines
  @max_width = max_width
  @participants = []
  @messages = []
end

Instance Method Details

#renderObject



369
370
371
372
373
374
375
376
377
378
379
# File 'lib/marvi/diagram.rb', line 369

def render
  return nil unless parse
  return nil if @participants.empty? || @messages.empty?

  grid = layout
  spans = grid.to_spans
  return nil if spans.empty?
  return nil if spans.any? { |line| Unicode::DisplayWidth.of(line.first.text) > @max_width }

  spans
end