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 before version 0.1.5 edges were simple hashes

Since:

  • 0.1.6

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = nil) ⇒ Edge

Create a new edge

Parameters:

  • attrs (Edge, Hash) (defaults to: nil)

Since:

  • 0.1.6



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

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

Since:

  • 0.1.6



118
119
120
121
122
123
# File 'lib/graph.rb', line 118

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 Edge’s attributes.

Returns:

  • Edge’s attributes

Since:

  • 0.1.6



94
95
96
# File 'lib/graph.rb', line 94

def attrs
  @attrs
end

Instance Method Details

#==(other) ⇒ Boolean

Compare two edges

Parameters:

Returns:

  • (Boolean)

Since:

  • 0.1.6



105
106
107
108
109
# File 'lib/graph.rb', line 105

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

    @attrs == other.attrs
end

#update(h) ⇒ Edge

Update the current edge, like the Hash#update method.

Parameters:

  • h (Hash)

Returns:

Since:

  • 0.1.6



114
115
116
# File 'lib/graph.rb', line 114

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