Class: DepGraph::Node
Overview
A node knows its dependables
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #<=>(other_node) ⇒ Object
- #dependencies ⇒ Object
- #depends_on(node) ⇒ Object
- #depends_on?(node) ⇒ Boolean
- #eql?(other_node) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(node_uri) ⇒ Node
constructor
A new instance of Node.
- #to_str ⇒ Object
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
#name ⇒ Object (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 |
#dependencies ⇒ Object
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
36 37 38 |
# File 'lib/node.rb', line 36 def depends_on? node @dependencies.include? node end |
#eql?(other_node) ⇒ Boolean
22 23 24 |
# File 'lib/node.rb', line 22 def eql? other_node (self <=> other_node) == 0 end |
#hash ⇒ Object
26 27 28 |
# File 'lib/node.rb', line 26 def hash @name.hash end |
#to_str ⇒ Object
14 15 16 |
# File 'lib/node.rb', line 14 def to_str @name end |