Method: Whence::Vertex#to_s

Defined in:
lib/whence.rb

#to_s(weight, last = true, indent = []) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/whence.rb', line 47

def to_s(weight, last = true, indent = [])
  my_indent = indent.dup
  child_indent = indent.dup
  if last
    my_indent.append("└")
    child_indent.append("  ")
  else
    my_indent.append("├")
    child_indent.append("│ ")
  end

  my_indent.join + " #{location} #{weight}\n" +
    @edges.each_with_index.map do |vertex_and_weight, i|
      vertex, weight = *vertex_and_weight
      vertex.to_s(weight, i == @edges.count - 1, child_indent)
  end.join
end