Class: Graph::Edge

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

Overview

An edge. This class is just a wrapper around a hash of attributes since in version <= 0.1.5 edges were simple hashes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = nil) ⇒ Edge

Returns a new instance of Edge.



91
92
93
# File 'lib/graph.rb', line 91

def initialize(attrs=nil)
    @attrs = attrs.is_a?(Edge) ? attrs.attrs : attrs || {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



107
108
109
110
111
112
113
# File 'lib/graph.rb', line 107

def method_missing(method, *args, &block)

    return @attrs[method.to_sym] if @attrs.has_key? method.to_sym
    return @attrs[method.to_s] if @attrs.has_key? method.to_s

    @attrs.send(method, *args, &block)
end

Instance Attribute Details

#attrsObject

Returns the value of attribute attrs.



89
90
91
# File 'lib/graph.rb', line 89

def attrs
  @attrs
end

Instance Method Details

#==(other) ⇒ Object

compare two edges

Parameters:



97
98
99
100
101
# File 'lib/graph.rb', line 97

def ==(other)
    return false if !other.is_a?(Edge)

    @attrs == other.attrs
end

#update(h) ⇒ Object



103
104
105
# File 'lib/graph.rb', line 103

def update(h)
    Edge.new super(h)
end