class Traver::Graph

Attributes

vertices[R]

Public Class Methods

new() click to toggle source
# File lib/traver/graph.rb, line 3
def initialize
  @vertices = {}
end

Public Instance Methods

[](key) click to toggle source
# File lib/traver/graph.rb, line 12
def [](key)
  key = key.to_s
  
  if plural?(key)
    vertices[key.singularize.to_sym]
  else
    name, index = key.split(/(\d+)$/)
    index = (index || 1).to_i
  
    vertices[name.to_sym][index - 1]
  end
end
add_vertex(key, object) click to toggle source
# File lib/traver/graph.rb, line 7
def add_vertex(key, object)
  vertices[key] ||= []
  vertices[key] << object
end
method_missing(method_name, *args) click to toggle source
# File lib/traver/graph.rb, line 25
def method_missing(method_name, *args)
  self[method_name]
end

Private Instance Methods

plural?(value) click to toggle source
# File lib/traver/graph.rb, line 32
def plural?(value)
  value == value.pluralize
end