Class: Dogviz::SequenceRenderer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title) ⇒ SequenceRenderer

Returns a new instance of SequenceRenderer.



8
9
10
11
12
13
# File 'lib/dogviz/sequence_renderer.rb', line 8

def initialize(title)
  @lines = []
  @indents = 0
  @rendered_class = RenderedSequence
  add_title title
end

Instance Attribute Details

#linesObject (readonly)

Returns the value of attribute lines.



6
7
8
# File 'lib/dogviz/sequence_renderer.rb', line 6

def lines
  @lines
end

Instance Method Details

#divider(text) ⇒ Object



49
50
51
# File 'lib/dogviz/sequence_renderer.rb', line 49

def divider(text)
  #nop
end

#end_combinationObject



36
37
38
39
# File 'lib/dogviz/sequence_renderer.rb', line 36

def end_combination
  @indents -= 1
  add_line 'end'
end

#note(from, where, what) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/dogviz/sequence_renderer.rb', line 41

def note(from, where, what)
  add_line "note #{where} of #{escape from.name}"
  @indents += 1
  add_line what
  @indents -= 1
  add_line "end note"
end

#render_edge(from, other, options) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/dogviz/sequence_renderer.rb', line 15

def render_edge(from, other, options)
  detail = options[:label]
  receiver_label = other.name
  sender_label = from.name
  annotations = nil
  if other.is_a?(Process)
    annotations = extract_annotations(detail, sender_label, receiver_label, other.description)
    receiver_label = process_start_label(receiver_label)
  elsif from.is_a?(Process)
    receiver_label = process_end_label(receiver_label)
  end
  line = "#{escape sender_label} -> #{escape receiver_label}: #{detail}"
  line = [ line, annotations ].join("\n") unless annotations.nil?
  add_line line
end

#renderedObject



53
54
55
# File 'lib/dogviz/sequence_renderer.rb', line 53

def rendered
  @rendered_class.new lines
end

#start_combination(operator, guard) ⇒ Object



31
32
33
34
# File 'lib/dogviz/sequence_renderer.rb', line 31

def start_combination(operator, guard)
  add_line "#{operator} #{escape guard}"
  @indents += 1
end