Class: Whence::Vertex

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location) ⇒ Vertex

Returns a new instance of Vertex.



38
39
40
41
# File 'lib/whence.rb', line 38

def initialize(location)
  @location = location
  @edges = Edges.new
end

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



36
37
38
# File 'lib/whence.rb', line 36

def location
  @location
end

#nameObject (readonly)

Returns the value of attribute name.



36
37
38
# File 'lib/whence.rb', line 36

def name
  @name
end

Instance Method Details

#<<(vertex) ⇒ Object



43
44
45
# File 'lib/whence.rb', line 43

def <<(vertex)
  @edges << vertex
end

#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