Class: Graph::Node

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

Overview

A node. This class is just a wrapper around a hash of attributes since in version <= 0.1.5 nodes were simple hashes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = nil) ⇒ Node

Returns a new instance of Node.



57
58
59
60
61
# File 'lib/graph.rb', line 57

def initialize(attrs=nil)

    @attrs = attrs.is_a?(Node) ? attrs.attrs : attrs || {}

end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



75
76
77
78
79
80
81
# File 'lib/graph.rb', line 75

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.



55
56
57
# File 'lib/graph.rb', line 55

def attrs
  @attrs
end

Instance Method Details

#==(other) ⇒ Object

compare two nodes

Parameters:



65
66
67
68
69
# File 'lib/graph.rb', line 65

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

    @attrs == other.attrs
end

#update(h) ⇒ Object



71
72
73
# File 'lib/graph.rb', line 71

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