Class: Whence::Vertex
- Inherits:
-
Object
- Object
- Whence::Vertex
- Defined in:
- lib/whence.rb
Instance Attribute Summary collapse
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #<<(vertex) ⇒ Object
-
#initialize(location) ⇒ Vertex
constructor
A new instance of Vertex.
- #to_s(weight, last = true, indent = []) ⇒ Object
Constructor Details
Instance Attribute Details
#location ⇒ Object (readonly)
Returns the value of attribute location.
36 37 38 |
# File 'lib/whence.rb', line 36 def location @location end |
#name ⇒ Object (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 |