Class: DepGraph::Node

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/node.rb

Overview

A node knows its dependables

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node_uri) ⇒ Node

Returns a new instance of Node.



8
9
10
11
12
# File 'lib/node.rb', line 8

def initialize(node_uri)
  fail 'Empty uris are not allowed' if node_uri.empty?
  @name = node_uri
  @dependencies = []
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/node.rb', line 6

def name
  @name
end

Instance Method Details

#<=>(other_node) ⇒ Object



18
19
20
# File 'lib/node.rb', line 18

def <=> other_node
  @name <=> other_node.to_str
end

#dependenciesObject



40
41
42
# File 'lib/node.rb', line 40

def dependencies
  @dependencies
end

#depends_on(node) ⇒ Object



30
31
32
33
34
# File 'lib/node.rb', line 30

def depends_on node
  node = Node.new(node) unless node.respond_to? :name
  
  @dependencies << node
end

#depends_on?(node) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/node.rb', line 36

def depends_on? node
  @dependencies.include? node
end

#eql?(other_node) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/node.rb', line 22

def eql? other_node
  (self <=> other_node) == 0
end

#hashObject



26
27
28
# File 'lib/node.rb', line 26

def hash
  @name.hash
end

#to_strObject



14
15
16
# File 'lib/node.rb', line 14

def to_str
  @name
end